Geert-Jan
Geert-Jan

Reputation: 18915

How to define transforms on a resource in a REST way?

I'm designing a REST api, following best practices, including a form of hypermedia/hateoas. I'm using jsonapi for the design guidelines, which seems to be pretty complete.

Currently, I have a need for:

  1. combining 2 resources in a response (a Resource A and a related Resource B). I do this using the Compound Documents - structure as specified in jsonapi. Or also commonly known as resource expansion
  2. formatting the result of 1. in a specialized way so it can be readily consumed by a specialized client that expects said formatting.

My problem is with 2. How do I correctly represent this in a REST-way? It seems I may need a separate endpoint, but that wouldn't be 'RESTy', since that implies a separate resource, while it's just a transformation of the output of the same resource.

Any references on how to do this?

Upvotes: 0

Views: 77

Answers (1)

Satish P
Satish P

Reputation: 524

You could use a header or a query param to handle this.

When the client needs specific formatting, they could add an additional header to the request something like Format:Indented or something like http:\\myapp.com\resouces\myresource?format=indented

Or if the server is formatting and wants the client to know that the response is pre-formatted, the server could add a Format response header to notify the client that response is formatted.

Upvotes: 1

Related Questions