'Does URL to REST API have to contain a path?

The POST method and path /pet is used to add a new pet to the store. And PUT method and path /pet is used to update an existing pet. If adding and updating pets is all the REST API does, does the /pet path have to be used to be RESTful? Or is it also a REST API if the path is removed and the endpoints are implemented as follows: The POST method and / is used to add a new pet to the store. And PUT method and / is used to update an existing pet. So instead of
https://www.my-restful-api-pet-store.com/pet
https://www.my-restful-api-pet-store.com/



Solution 1:[1]

Does URL to REST API have to contain a path?

REST just says "use resource identifiers".

HTTP Semantics defines the two familiar URI schemes

http-URI  = "http"  "://" authority path-abempty [ "?" query ]
https-URI = "https" "://" authority path-abempty [ "?" query ]

Where path-abempty is defined by RFC 3986

path-abempty  = *( "/" segment )
segment       = *pchar

In HTTP/1.1, a request-line needs a request-target, and in origin-form you need an absolute-path

absolute-path = 1*( "/" segment )

So all of these are fine

/
//
//apple
/banana/

Any information that can be named can be a resource

If you want to have a single "most recently modified pet" resource in your resource model, that's fine. And the identifier for that resource can be anything that you want (subject to the production rules described above).

BUT... that resource model gives up a lot of the power that is built into the general purpose HTTP application protocol.

Most designs instead choose to have many different cacheable documents, and you send information to the server by editing a specific document. In other words, instead of sending information to the server by editing the "most recently modified pet" document, we edit the "Doug" document when we are sharing information about Doug.

Webber 2011 discusses the distinction between using an unbounded set of operations and an unbounded set of resources.

When you are in the REST architectural style, you'll normally want to take the path with an unbounded set of resources.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 VoiceOfUnreason