Create Restfull Service with method POST

One Star

Create Restfull Service with method POST

Hi all,
I have to create a Rest Service with method POST. This service, for the moment, hasn't input and returns a JSON that I have set from a file like shown in figures.
I tried this service by Rest Client, but it returns status code "415 Unsupported Media Type".
Someone could show me an example with method post?
thanks
Employee

Re: Create Restfull Service with method POST

Hi
You have the endpoint that expects HTTP Content-Type set to application/json or application/xml, 415 would be returned if it is set to something else, example, some clients may set a form Content-Type if no Content-Type is set.
HTH, Sergey
One Star

Re: Create Restfull Service with method POST

Hi,
if I want to send a JSON input to Rest Service, as shown in figure, how Can I set the JSON in the rest client??
{"file":"content"}

Is it correct?
Employee

Re: Create Restfull Service with method POST

Hi, I guess you have 2 options:
- set tRESTClient body type to String and use a tWriteJsonField component
- use tXmlMap to build XML tree and then let tRESTClient auto-convert it to JSON, keep the body type as Document
Cheers, Sergey
One Star

Re: Create Restfull Service with method POST

Hi Sergey,
I don't use tRestCLient, but I want to use Advanced Rest Client. For this reason, I have to know the format for the JSON to send to Service.
Employee

Re: Create Restfull Service with method POST

Hi, it depends on what format tRESTRequest expects.
If it has to be
{"file":"content"}

then have Advanced Rest Client produce it,
Cheers, Sergey
One Star

Re: Create Restfull Service with method POST

I tried by advanced rest client with:
{"file":"content"}

but it return status code "415 Unsupported Media Type".
Why? How have to configure tRestrequest?
thanks a lot.
Employee

Re: Create Restfull Service with method POST

First of all, can you please vote for
https://jira.talendforge.org/browse/TESB-15346
OK, so you have this JSON payload. The 1st thing that needs to be done is to have it mapped to a schema parameter called 'body' - so add a 'body' parameter there of either String or Document type.
If you choose String - it means you need to process it with one of components which can take a JSON string and process it,
If you choose Document - it means tRESTRequest will try to auto-convert JSON into a Document which you can later process with tXMLMap, etc.
In this specific case make sure you set tRESTRequest wrap json sequence property to true to get the auto-conversion working.
Please also make sure Advanced Rest Client sets Content-Type to application/json - one way to check is to enable TRESTRequest to log the incoming requests
HTH, Sergey