json-ld response convert to regular json

Not applicable

We are creating a proxy to a source that supplies the data in json-ld.

We would like it to be regular json - can we force the headers in the proxy flow somehow?

Many thanks

0 5 266
5 REPLIES 5

Hi @James Askew do you want to Set/Add/Modify/Remove a header in the proxy and forward it to the target?

We can do that by using the Assign Message Policy.

https://docs.apigee.com/api-platform/reference/policies/assign-message-policy#setelement-setheaderse...

Good question, yes and i guess i want to set the headers, but trying Dino's approach below didnt work for me, but its possible i was appending to the wrong part of the flow.

As the below didnt work, i am going to investigate the target, and see if its that thats not playing ball - thank you

Does your source have any logic to give/produce regular json when the request contains a specific header?

you want to change

Content-Type: something

to

Content-Type: application/json

?

Use AssignMessage.

<AssignMessage name="AM-CORSResponse">
    <Set>
        <Headers>
            <Header name="content-type">application/json</Header>
        </Headers>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="response"/>
</AssignMessage>

Thanks Dino, that looks like it should have done the trick but had no luck.

Am going to investigate the source, to see if its that that is not playing ball / force it to be json naturally if possible.

Incidentally which part of the flow should the assignMessage have been applied to? I tried what seemed like all 4 parts to no effect.

By the way thanks for the 7 part video series you did. Was absolutely spot on for getting started. Cheers