How to structure an API where the same data may request in different format, in a RESTful format. For example.
GET /person/<id> //get the details of resource <id>
Now depending on the client (browser) requirement, the data may send as html (say normal rendering) or Json (say ajax call). So my doubts are
- Can I keep the same url for both requests, or should keep them seperate?
- How to detect whether the request is for html/Json at the server. The request type is same (GET). So which parameter should I consider.
- How to detect the difference in data type at client (html/Json)\
thanks,
bsr.
Similar question: REST Content-Type: Should it be based on extension or Accept header?
The accepted answers has great points.
Yes, keep them the same. Its the same resource, you’re just asking for different representations of it.
You can use the Accept header to specify the return content-type.
You would look at the “Content-Type” header.