I've been looking through various solutions for converting JSON responses to string, but I'm still getting something wrong.
I'm trying to read the response from a post request, convert it to a string and modify it (using groovy), then pass it on the next request. The problem seems to be in the groovy script, it's not reading in the response from the first HTTP request and I'm not sure how to fix that.
Related
I have to append parameter in JSON response after request processing is completed and before sending. I can do in after exec filter. Here I defined filter like this,
beego.InsertFilter("*", beego.AfterExec, AddRequestAfterExec, false)
Now in this AddRequestAfterExec method, I am unable to read JSON response. I need to read JSON response and add parameter to it. I searched many things, but did not find any thing useful. So far I have left it empty.
func AddRequestAfterExec(c *context.Context) {}
Can anybody help, how to read Response in this function and modify it?
Also I am sending response from API controller like this
authController.ServeJSON()
Recently, Iv'e been using the Joi validation library in-order to validate the data which comes in from a request (building a RESTful API).
I was using the .label() method to generate a string response and send it back to the user, but I couldn't find any way to send a JSON response back to the user?
Tried sending a premade JSON inside the string, searching the documentation and the internet of course - couldn't find any mention of it.
Current code example:
textField: Joi.string().required().max(4).label("This example field didn't pass the testing phase, please try again)"),
Any ideas?
If you need to send data in case of error,try .error() method. you can pass error in it.
How to read JSON object response from the server?
These are the commands I use:
AT+SAPBR=3,1,"Contype","GPRS"
AT+SAPBR=3,1,"APN","internet"
AT+SAPBR=1,1
AT+SAPBR=2,1
AT+HTTPINIT
AT+HTTPSSL=1
AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","https://www.mywebsite.com/getTime?token=jsdaljdaskl"
AT+HTTPPARA="REDIR",1
AT+HTTPACTION=0
The returning request should be Json object, but the Sim808 read it as html response which gives error 606.
Need to define HTTP parameter content as JSON format using the following command
AT+HTTPPARA="CONTENT","application/json"
Found this document useful HTTP Client using SIM900.
I have a question regarding REST Assured. - https://code.google.com/p/rest-assured/wiki/Usage
I understand that I can use REST assured to make HTTP calls(.get .put etc.) and validate the response using when() etc. I would like to validate JSON responses that I have already saved in the database, instead of Calling the web service realtime and validating it's response.
Can I use REST-assured to Load a JSON response as a String and validate it?
Yes you can use Rest Assured's JsonPath project independently of Rest Assured (see getting started page). Once you have it in classpath you can do something like this:
JsonPath jsonPath = new JsonPath(<your json as string>);
String title = jsonPath.getString("x.y.title");
I am trying to consume flickr api and requesting data in json format from a node.js server. I am providing nojsoncallback=1 so that returned json is not wrapped inside a jsonp callback. Here is the url http://api.flickr.com/services/feeds/photos_public.gne?format=json&nojsoncallback=1.
Json returned is not properly formatted and JSON.parse is unable to parse it. If I don't pass nojsoncallback query param and eval the response which calls jsonFlickrFeed function, it gets evaled properly and I get the object. I also notice that the Content-type header in the response is application/x-javascript; charset=utf-8. I suspect that the special characters are double escaped in returned response.
I don't want to eval, what can I do to convert the response correctly into a string and then parse it?
By the way here is the gist with simplest use case. No modules, no middlewares.