REST API Resources

Creating my first REST API, and I have a question. I have a place for the resource:

/venues

Each institution has guests:

/venues/1/guests

That's where I got confused. If I want to update a guest resource, is it better to do this:

POST /venue/1/guests/1/

or

POST /guests/1

The second option is shorter, and the guest identifiers are unique, the second is excellent. But first, clearer.

So, I'm stuck on which route to take from here.

thank

+3
source share
2 answers

Both are pretty much the right approaches, although if you guarantee to clients (client developers) that guest identifiers will always be unique no matter where they visit, I will go with

POST /guests/{guestId}

I usually use this:

POST /venues/{venueId}/guests/{guestId}

. , id 1 RSVP "" Id 1, URL- ( , , , / - RSVP):

POST /venues/1/guests/1
request body: {"RSVP", true}

, , ,

PUT /guests/1
request body: {"firstName":"John","lastName":"Foo"}

, !

+2

, RESTful

  • A)
  • B)

POST/GET/DELETE/PUT ( CRUD)

POST /venues/
GET /venues/
POST /guests/
GET /guests/

CRUD ,

POST /venues/[venue-id]/guests/[guest-id]/
+1

All Articles