I'm trying to create an API that follows REST best-practices, is intuitive, and matches what patterns developers see from other (well-designed) APIs. I believe I understand the various mapping of the HTTP verbs to the typical resources, which is in line with the answers in these two questions:
Which HTTP methods match up to which CRUD methods?
Understanding REST: Verbs, error codes, and authentication
Where I'm having trouble is that, due to the nature of our business and the data required to retrieve data, which would normally be a GET, we need to use a POST. This is due to both the size of the request, as well as what we're passing in order to do the search.
When do you use POST and when do you use GET?
So, there are a couple approaches I can think of on how to best handle CRUD, and I've love some suggestions:
- Use query parameters in the POST for differentiating CREATE vs READ, other verbs as normal. Don't love this idea.
- Have a separate endpoint for each action, e.g. /baseUrl/lookup, /baseUrl/create. Doesn't follow the proper pattern of using nouns instead of verbs.
EDIT: In the interest of clarity, the contrived example in my comments of an image lookup service, where a caller can search if an image is already in the database, add a new image, update the image (e.g. add metadata), or delete the image.
Create: What should we do here? POST /image/create and update the Read endpoint to /image/search?
Read: POST /image { imageData = someBase64EncodedImage }
Update: PUT /image/{imageId}
Delete: DELETE /image/{imageId}