Format response as HAL+JSON

Has anyone setup their proxy to change a target endpoint json response to a hal+json response? If so, could you share how you did it? We are trying to use this js library - https://github.com/byteclubfr/js-hal but are running into js include issues.

Solved Solved
0 4 511
1 ACCEPTED SOLUTION

I implemented converting the target endpoint json response into a hal+json response by using a nodejs HostedTarget and using the hal-serializer library.

View solution in original post

4 REPLIES 4

Could you provide the JS policy and the error descriptions.

BTW the sample module is availble in Nodejs, did you try that one?

What does this mean?

to change a target endpoint json response to a hal+json response?

Can you give an example or two to show specifically how you would want to change the response?

So an example might be a customer response object coming from the Target Endpoint which returns a Customer object with a child object of Orders. We don't want to include the Orders object in the response to the client, just a link to it. Our API guidance for HATEOUS implementations is to use hal+json media type.

Here's a simple example response.

Response from Target Endpoint:

{ 
	"id":123456,
	"firstName":"Joe",
	"lastName":"Smith",
	"orders":[{
		"id":123,
		"total":100.00
	},
	{
		"id":155,
		"total":300.00
	}]
}

We want to transform that Target Endpoint response to a hal+json media type response:

{ 
	"_links": {
		"self": { "href": "/customers/123456" }
	},
	"id":123456,
	"firstName":"Joe",
	"LastName":"Smith",
	"_embedded": {
		"orders": [{
			"_links": [{
				"self": { "href": "/orders/123" }
			}]
		}, {
			"_links": [{
				"self": { "href": "/orders/155" }
			}]
		}]
	}
}

I implemented converting the target endpoint json response into a hal+json response by using a nodejs HostedTarget and using the hal-serializer library.