Jon
Jon

Reputation: 83

URL to REST resource with a composite ID

I’m creating a REST API where some of my resources have a composite ID made of two separate parts. An example is a resource for a given latitude and longitude.

My initial thoughts were to add each composite part of the ID as a separate part of the path as per below:

http://localhost/phone-details/Vodafone/07123000000 - Operator and number

http://localhost/location-details/50/-2 - Lat and long

Is this best practice to take this approach? Should perhaps query strings be used so each composite ID part has a clear and obvious name? Alternatively should the composite IDs just be passed across separated by a comma?

Upvotes: 2

Views: 3218

Answers (1)

ishenkoyv
ishenkoyv

Reputation: 673

I can suggest you good book Restful web services cookbook From there (p.77)

Use the comma ( , ) and semi-colon ( ; ) characters to indicate nonhierarchical portions of the URI.

The semicolon convention is used to identify matrix parameters:

http://www.example.org/co-ordinates;w=39.001409,z=-84.578201 http://www.example.org/axis;x=0,y=9

Upvotes: 5

Related Questions