Working on the API, I understood that the behavior for one of the endpoints might be a bit counter-intuitive, but I am not sure whether this violates any RESTful rules. Based on what I have read, it doesn't directly but probably that's a bad practice anyway.
I have an endpoint, say,
/items for which there are two methods: GET (returns all existing entries) and POST (creates a new entry).
This is not a straightforward CRUD because getting an item results in a query that joins several tables and returns them in a user-friendly manner.
Creating an item requires sending a payload with a list of objects (not of type
Intuitively, it seems that the most logical way is to expect an object you want to create and then receive it in the response. In my case, however, the payload in the request contains the list of objects that are used to correctly create an
item that can further be returned (and it will be an array of objects because there might be several rows created as a result).
To sum up:
- Is it okay for a POST request to send objects in the payload other than what you expect to be created?
- Is it okay to return an array of objects (I assume the answer is most likely yes)?
I know that POST requests are often used for all non-standard types of requests but I would like follow the best practices as long as possible :)