You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: topics/restful.md
+78
Original file line number
Diff line number
Diff line change
@@ -45,6 +45,84 @@ Treat it like a sub-resource with RESTful principles. For example, GitHub's API
45
45
46
46
Sometimes you really have no way to map the action to a sensible RESTful structure. For example, a multi-resource search doesn't really make sense to be applied to a specific resource's endpoint. In this case, /search would make the most sense even though it isn't a resource. This is OK - just do what's right from the perspective of the API consumer and make sure it's documented clearly to avoid confusion.
47
47
48
+
# Naming Convention
49
+
50
+
Use consistent resource naming conventions and URI formatting for minimum ambiguily and maximum readability and maintainability. You may implement below design hints to achieve consistency:
51
+
52
+
### **Use forward slash (/) to indicate a hierarchical relationships**
53
+
54
+
The forward slash (/) character is used in the path portion of the URI to indicate a hierarchical relationship between resources. e.g.
It’s possible to use an underscore in place of a hyphen to be used as separator – But depending on the application’s font, it’s possible that the underscore (_) character can either get partially obscured or completely hidden in some browsers or screens.
84
+
85
+
To avoid this confusion, use hyphens (-) instead of underscores ( _ ).
When convenient, lowercase letters should be consistently preferred in URI paths.
95
+
96
+
RFC 3986 defines URIs as case-sensitive except for the scheme and host components. e.g.
97
+
```
98
+
http://api.example.org/my-folder/my-doc //1
99
+
HTTP://API.EXAMPLE.ORG/my-folder/my-doc //2
100
+
http://api.example.org/My-Folder/my-doc //3
101
+
```
102
+
In above examples, 1 and 2 are same but 3 is not as it uses My-Folder in capital letters.
103
+
104
+
### **Never use CRUD function names in URIs**
105
+
106
+
URIs should not be used to indicate that a CRUD function is performed. URIs should be used to uniquely identify resources and not any action upon them. HTTP request methods should be used to indicate which CRUD function is performed.
107
+
```
108
+
HTTP GET http://api.example.com/device-management/managed-devices //Get all devices
109
+
HTTP POST http://api.example.com/device-management/managed-devices //Create new Device
110
+
111
+
HTTP GET http://api.example.com/device-management/managed-devices/{id} //Get device for given Id
112
+
HTTP PUT http://api.example.com/device-management/managed-devices/{id} //Update device for given Id
113
+
HTTP DELETE http://api.example.com/device-management/managed-devices/{id} //Delete device for given Id
114
+
```
115
+
116
+
### **Use query component to filter URI collection**
117
+
118
+
Many times, you will come across requirements where you will need a collection of resources sorted, filtered or limited based on some certain resource attribute. For this, do not create new APIs – rather enable sorting, filtering and pagination capabilities in resource collection API and pass the input parameters as **query parameters**. e.g.
Always use SSL. No exceptions. Today, your web APIs can get accessed from anywhere there is internet (like libraries, coffee shops, airports among others). Not all of these are secure. Many don't encrypt communications at all, allowing for easy eavesdropping or impersonation if authentication credentials are hijacked.
0 commit comments