Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm creating a RestFul API for the first time using spring framework and now im a bit confused about the common labels used to create, read, update and delete. I want to follow a pattern for an easy maintenance in the code. Is there any rule or naming pattern for the labels that I should follow?

Im thinking about:

/service        -> return every services
/service/new    -> create new service
/service/update -> update service
/service/delete -> delete service
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
233 views
Welcome To Ask or Share your Answers For Others

1 Answer

Use the HTTP verb to control what you want to do with the resouces:

GET:    /services        -> returns all elements
GET:    /services/{id}   -> returns element with id
POST:   /services        -> creates a new object, pass the object in the body
PUT:    /services/{id}   -> updates element with id, pass updated values in body
DELETE: /services/{id} -> delete element with id

I strongly recommend you use query params for paging in GET: /services, return a default number on page 1 if it's not listed.

A full request could look like: http://www.example.com/services?page=5&count=10


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...