rest api best practise

来源:互联网 发布:人工智能计算器v3.6.0 编辑:程序博客网 时间:2024/06/05 10:05

Mainly cited from http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api with my thinking.


1.always use nouns.

2.always use ssl.

3.prefer post to put.

4.version your api.

5.internal filtering, sorting, searching.(this needs to think more in real use case scenario)

6.update/create return 201 with location.

7.json only response.

8.prefer return gzip in response.

9.set rate limiting.

10.rest api is always stateless.(no cookies or sessions)

11.if use ssl, just simple genereate auth token or use oath(= =)

12.the representation of any errors should be the same as any resources.

13.400 series status code for client issues, 500 series for server issues.

14.the error content should include { errorcode, message, details, suberrors[] }.


Finally, rest api is the ui to the developers, make it pretty and easy to use:-)

0 0