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: restful_api.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,23 +18,23 @@ What's the point of all this? Come on, be professional!
18
18
### Endpoint Design
19
19
20
20
- Keep in mind that REST is **resource oriented**, do not design endpoints casually.
21
-
- Use **plural noun** as path for resource collection, like `/blogs`.
22
-
- To represent a single resource out of a collection, use path like `/blogs/{id}`. The `{id}` is the unique identity(database id, unique name, etc) of a resource, and don't repeat the `{id}` in other request parameters.
21
+
- Use **plural noun** as path for resource collection, like `/articles`.
22
+
- To represent a single resource out of a collection, use path like `/articles/{id}`. The `{id}` is the unique identity(database id, unique name, etc) of a resource, and don't repeat the `{id}` in other request parameters.
23
23
- Use HTTP verbs right, common CRUD cases:
24
24
25
25
Resource Path | POST | GET | PUT | PATCH | DELETE
26
26
-------- | ---- | --- | --- | ----- | ------
27
-
`/blogs` | create a new blog | list blogs | X | X | X
28
-
`/blogs/{id}` | X | get a blog by id | update or create(if not exists yet) a blog by id | update a blog partially by id | delete a blog by id
27
+
`/articles` | create a new article | list articles | X | X | X
28
+
`/articles/{id}` | X | get a article by id | update or create(if not exists yet) a article by id | update a article partially by id | delete a article by id
29
29
30
-
- Resources can be nested, e.g. `/blogs/{blogId}/comments/{id}`, but not necessary, `/comments/{id}` is also ok, this is more a matter of style.
31
-
- In some cases a property of a resource can be represented as a resource too, e.g. `PUT /blogs/{id}/title`.
32
-
- Arbitrary meaningful information can be inserted into the resource path, e.g. `/it/blogs`(site category route), `/blogs/hot`(collection quick filter, only for `GET`), even `/it/blogs/hot`.
30
+
- Resources can be nested, e.g. `/articles/{articleId}/comments/{id}`, but not necessary, `/comments/{id}` is also ok, this is more a matter of style.
31
+
- In some cases a property of a resource can be represented as a resource too, e.g. `PUT /articles/{id}/title`.
32
+
- Arbitrary meaningful information can be inserted into the resource path, e.g. `/it/articles`(site category route), `/articles/hot`(collection quick filter, only for `GET`), even `/it/articles/hot`.
33
33
- A resource can be singleton without parent collection, e.g. `GET /appVersion`.
34
34
- For unusual non-CRUD cases, always use POST + verb-ended path, e.g.:
0 commit comments