I have a REST API Endpoint endpoint/action. The method is POST having a json data in the request body. I have two headers for this
Content-Type=application/json
Custom-Header={"object":{"id":"someId"}}
The object is deserialized during processing and the "someId" is used for other processes
Was wondering if it is a good practice to send json strings/data in the http header. Couldn't find anything in the Http Header documentations.
Option would be just sending in the "someId" and fetching the object using the id
Related
I am always getting JSON response for my HTTP request to access one ORDS-Oracle Rest Data Services API:
http://localhost:8080/ords/hr/employees/
However my requirement is to get XML response. I tried to choose XML from drop down list available at POSTMAN, however content is not changing to XML.
I need a way to specify parameter as part of HTTP URL so that response is XML than JSON and I tried to change URL like below:
Way1:
http://localhost:8080/ords/hr/employees?format=xml
Way2:
http://abcdef.us.oracle.com:8001/claims-ws/api/generic/lineofbusinesses/421?Content-Type:application/xml
Way3:
http://abcdfef.us.oracle.com:8001/claims-ws/api/generic/lineofbusinesses/421?Accept:application/xml
Way4:
http://abcdef.us.oracle.com:8001/claims-ws/api/generic/lineofbusinesses/421?Accept=application/xml
However nothing is working and response is always JSON.
Any suggestion?
I have a POST API consuming JSON Object. I need to pass the JSON as body data to the API. The conversion of JSON Object to the intended class object is failing. Do we have to specify any other parameters?
You have to specify Content-Type header to application/json using HTTP Header Manager (add it as a child to the HTTP sampler of POST request), so that JMeter sends the POST request telling the server that the body contains JSON using the header.
Let's say I'm making the http request below, to update some record in a mongoDB database:
PUT
http://dev.mycompany.co/ping
{"id":4432, "name":"Jane Doe", "products":[ {"id":287}, {"id":434} ] }
Notice that there is an array of two objects inside the "products" property of the JSON above. I have data that is being sent in this general format, both through Fiddler and through a ruby script I've written.
When sent through Fiddler, my data in the JSON is correctly parsed and updated into my database. When sent through my ruby script, the data in the JSON is not parsed correctly. I've been trying to figure out why this is. Now, I'm wondering how data is actually sent when a JSON is sent along with an http request. Can someone point me in the right direction?
After asking a few other questions on SO and doing a bunch more research, I've arrived at the following conclusions.
Q: How does JSON data get sent in an http request?
A: It depends on how you are sending the JSON data in the request (what is the content-type)
I've encountered two ways that JSON data is sent.
Sent using content-type application/json
With this content-type, JSON data is sent literally as-is. The literal JSON data is stored as a string and sent with the request. If your JSON is complex, with nested objects and arrays and such, this is probably what you want. For a working example of sending nested JSONs using Ruby's Net/HTTP, see the answer on this SO question I asked.
Sent using content-type x-www-form-urlencoded
This is how Ruby's Net/HTTP requests typically get sent out. The form of these requests is something like: id=343?entity=Microsoft?foo=bar. This content-type is fine until you have a complex JSON.
The client (Browser) expects to receive a JSON string in response. I have the JSON string to send at the service side. However the calling function (axis2_invoke) expects axiom_node_t which make it return XML.
Is there a way to send my response in a way I want to and not as axiom objects
AxiOM is a data abstraction layer, not XML.
When talking about Axis2/C-unofficial which supports JSON natively, you will get response depending of your request format:
if you setup Content-Type of your request to application/json you will get response in JSON format;
if you setup Content-Type of your request to application/soap+xml you will get response in SOAP format.
Your response AxiOM is to be be converted to appropriate format by Axis2/C's transport sender.
I have an issue trying to make a cross-domain ajax request for a json file. I can reach the file using jsonp, but on the client-side there is no jsonp response, and I have no control over changing that.
Is there a way to reach the file without cross-domain issues, through jsonp request, but then receive the response as json and parse it as json?
No, the response must be a function invocation. This is the basis of the JSONP convention. If you want access to some JSON data from your JSONP call, simply have the response invoke a function on your page, passing in the desired JSON data as a parameter.