简体   繁体   中英

Create PUT and POST endpoints in a REST API, without creating a GET endpoint?

I am writing the endpoints for a resource items , that is a subresource of applications , like this: applications/{:id}/items . Both, items and applications have other properties apart from their name.

I have created

  • GET applications/{:applicationId}/items - returns the list of items that belong to an application

  • POST applications/{:applicationId}/items - creates an item for an application

  • PUT applications/{:applicationId}/items/{:itemNumber} - updates an item of an application

The clients are generally only interested to see a list of items for an application and not individual items, so my team thinks that creating the endpoint

GET applications/{:applicationId}/items/{:itemNumber}

is unnecessary. I am wondering if it is a bad idea not to create such an endpoint considering that we already have POST and PUT endpoints for the same resource.

It is perfectly acceptable to create a PUT without a matching GET.

If you find that you need it at a later date you can add it; if however you create it before you need it, you will be carrying code which is neither needed nor used, but you will still have to maintain and test it.

If you don't want to test or maintain it, then you should delete it.

THERE ARE NO BUGS IN DELETED CODE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM