Greg
Greg

Reputation: 6628

How can I specify available GET params in OPTIONS verb?

In REST webservice there is a possibility to say which verbs are possible for specified resource. Can I return any headers specifying that for GET one could pass param, say, 'name' so client knows that he could make: GET /resource?name=foo

Upvotes: 0

Views: 188

Answers (1)

fumanchu
fumanchu

Reputation: 14559

You can make new headers if you like, but they wouldn't be very much in line with the design of the protocol. First of all, it's important to understand that "/bar" identifies a resource, and "/bar?name=foo" identifies a different resource, not the same resource with parameters. I know this is counter to the design of many popular web frameworks, but it's essential for understanding how to use the protocol correctly.

Based on that, the OPTIONS method should return information about the identified resource, which means that OPTIONS /bar should return a response about the communication options of the /bar resource, not the /bar?name={name} set of resources. Note also that OPTIONS has no format specified for a payload; the only interoperable exchange is via well-known headers like Allow.

The proper way for a representation of the resource /bar to contain information about the resource /bar?name=foo is via links (or forms, some of which are a means to construct links), either in the payload (if the media type supports it) retrieved from GET /bar, or in the response headers (more and more commonly via the Link header). Look into URI Templates for an alternative to HTML forms.

Upvotes: 1

Related Questions