Architectural design for REST API with resource view

Look for some input on the architectural design of the REST API. I often find that the required data is a combination of representing several resources. Do you expect the client to combine them or provide an API that performs the combination for the client?

For example, let's say we write a REST API for people to receive event notifications. Someone will show interest in the event in one of two ways:

  • Join an organization that regularly posts events that a person is interested in.
  • Search and then mark a specific event performed by the organization, I usually did not subscribe to

I can get all the events for the user 100by following these long steps:

  • GET /user/100/organizations returns 123
  • GET /organizations/123/events returns [15,16,20]
  • GET /user/100/savedevents returns [35,36]
  • GET /events/15,16,20,35,36 returns all events

But it seems rather difficult for the client. I almost want the client to be able to say: "Give me all the interesting events for this user":

GET /user/100/events

... and then ask the server to understand that it must go through all stages 1-4 and return them, or at least return [15,16,20,35,36]it so that it becomes 2 steps: get event identifiers; Get information about the event.

Does it make sense to make a view that crosses multiple resources in this way?

EDIT: Explain in more detail. My hesitation is what I see as /organizations/123/eventsa pure resource; if this is the same as saying /events?organizations=123, i.e. "give me resource events where organizations = 123." The same for /user/100/organizations.

/user/100/events " , = 123". " , = 100, , , = 123, , = 100".

- . . ( -), !

+1
2

... , , ( ), REST (.. , ), , , API).

, , , REST API "" "" - ( "savedevents" ), . - :

  • POST /user/{username}/events ( ),
  • GET /user/{username}/events , .
  • GET /user/{username}/events/{eventid}

"" ( ), " ":

  • GET /user/{username}/events?organization=123

, ( API) 1 4 GET /user/{username}/events. ( "" "" ) API, (, ..).

0

, , , , , , = P.

, . , , API, ?

RESTful , .

RESTful - CRUD (, , , ) HTTP- (, GET, POST, PUT, DELETE). - cookie (, " bob", " ", " " ), REST.

, RESTful development, - , RESTful, ; GET , POST , PUT , DELETE ).

, - 1 4, - :

GET /user/{userID}/organizations --> {return all affiliated organizations}
GET /user/{userID}/events --> {return all events associated with userID}
GET /organizations/{organization}/events --> {returns all eventID assoc. with organization}
GET /user/{userID}/savedevents -->  {return all eventID userID saved to their profile}
GET /events/?eventID=(15,16,20,35,36) --> {return all of the events details for those eventID's}
GET /events/{eventID}--> {return events details for {eventID}}

:

GET /events/  --> {return a complete listing of all event ID's}
GET /events/{userID}  -->  {return all events userID is associated with}
POST /event/  --> {create a new event - ID is assigned by the server}
POST /user/   --> {create a new user - ID is assigned by the server}
PUT /user/{userID}  --> {update/modify user information}

, , ( ). (Random FYI, - ).

:

. , , //123/ - ; /events? organization = 123, " , = 123". /user/100/.

, named resourced resource + argument . , API- API RESTful , ( , , ..). , / , . API, RESTful HTTP-. , ...

/events?organizations=123 -->  {return the eventID associated with org=123}
/organizations/123/events  -->  {return event DETAILS for events associated with org=123}

/, Apigee

+2

All Articles