Deb
Deb

Reputation: 1

In a REST API, can i split a Resource identifier between path and querystring parameters?

The REST resource in my REST API is Account. The Account's ID is a combo key made unique by cid (customer ID), SalesOrg, and CompanyCode. If I wanted to have the combo ID in the path parameter, I realize that one way is to use delimiters between different elements which constitute my Combo Id. Something like 123~BSD~11, or may be cid~123^salesOrg~GBS^companycode~11. Instead, I thought of having a REST URI with cid in the path parameter, and SalesOrg and CompanyCode in the querystring. Something like below,

/v1/Accounts/{cid}/contacts?SalesOrg=BSD&CompanyCode=11

So, I am proposing using one of the constituents of my combo ID in path parameter and remaining constituents of the combo id in Querystring. Is this a valid REST architectural practice? If no, under what circumstances is my proposal acceptable?

Upvotes: 0

Views: 333

Answers (1)

VoiceOfUnreason
VoiceOfUnreason

Reputation: 57257

In a REST API, can i split a Resource identifier between path and querystring parameters?

Yes - the URI is an identifier; from the perspective of clients and intermediate components it is opaque, which means that the server can encode into the URI, at its own discretion and for its own exclusive use, any data that it chooses.

Both the path and the query are included in the request line of an HTTP request, so you have your choice of deciding which data to include in which of those parts.

Encoding information that the server needs into the fragment would not be productive, because that information is not included in the HTTP request at all.

I am proposing using one of the constituents of my combo ID in path parameter and remaining constituents of the combo id in Querystring. Is this a valid REST architectural practice?

Perfectly acceptable.

Upvotes: 1

Related Questions