I am trying to build a query, and pass parameters to it,
not sure how can I do it, here is my query
{ "object": "garages", "q": { "lat_long" : { "$within" : [[28.703341,77.130605],10000] } } }
I am passing lat,lng and radios.
Now I am able to pass the params, however in response I get lat_long
as "lat_long": "AAAAAAEBAAAAVYSbjCqfPEDyzTY3pkVTQA==" .
Is it encoded / serialized? How can I'll get my original values?
Thank you,
Point is stored as a binary value, in order to see your original values you have 2 option
You can manipulate the sql statement like this :
SELECT CONCAT(X(lat_long), ',', Y(lat_long)) as origin
FROM garages WHERE (ST_Distance ..........
but this way you want be able to edit the nosql tab
When you call REST API With 'GET' on object 'garages' you'll see the values as you oroginaly Posted them
Related
I am recording a Receipt-Accept scenario(Unique Number) in JMeter. Once the recording was done Jmeter fetching some values from DB like the below:
POST data:
{
"pItemID": 8793120,
"pShipHeaderID": 41343933,
"pHeaderID": 37123507,
"pLineID": 45338365,
"pRCVTransID": 113927590,
"pOrgCode": "E90",
"pRelnum": null
}
this will be unique for each receipt. I don't know which value will come for the next receipt. How can I handle this?
POST data:
{
"pItemID": 8793120,
"pShipHeaderID": 41343933,
"pHeaderID": 37123507,
"pLineID": 45338365,
"pRCVTransID": 113927590,
"pOrgCode": "E90",
"pRelnum": null
}
[no cookies]
I expect the values present under "POST data" should dynamically change in the run time.
You could use the random function to generate a random value and use the same
{
"pItemID": ${__Random(0,7)},
}
Please check the link bellow for more information on Jmeter functions and variables
https://jmeter.apache.org/usermanual/functions.html#__Random
I'm fairly new to REST. All of our legacy webservices were SOAP based with enterprise (ORACLE or DB2) databases. We are now moving to REST/couchbase.
Our team is looking into implementing a complex query method. We already have implemented simple query methods using GET, for example GET returns all entries and a GET/067e6162-3b6f-4ae2-a171-2470b63dff00 would return the entry for 067e6162-3b6f-4ae2-a171-2470b63dff00.
We want to support a query method that would support receiving several query parameters such a list of Ids and date ranges. The number of Ids can number into a few thousand and because of this, we realize we cannot pass these query parameters in a GET HTTP header since there is a limit on header size.
We are starting to look into passing our query parameters into the JSON body of a POST request. For example, we could have client pass in a few thousand Ids as an array and also pass in a date range, so we'd have each query param/filter be an object. The JSON body would then be an array of objects. For example:
{
"action" : "search",
"queryParameters" : {
[
{
“operation”: “in”,
"key" : "name.of.attribute.Id",
"value" : "[{ "id: "067e6162-3b6f-4ae2-a171-2470b63dff00"}, {"id": "next id"....}],
},
{
“operation”: “greater”,
"key" : "name.of.attribute “,
"value" : "8/20/2016"
},
{
“operation”: “less”,
"key" : "name.of.attribute “,
"value" : "8/31/2016"
}
]
}
The back end code would then receive POST and read the body. It would see action is a search and then look for any entries in the list that are in the list of Ids that are in the date range of > 8/20/2016 and < 8/31/2016.
I've been trying to look online for tips/best practices on how best to structure the JSON body for complex queries but have not found much. So any tips, guidance or advice would be greatly appreciated.
thanks.
I'm using an Express server with RethinkDB, and I want to send in multiple coordinates into my 'locations' table on RethinkDB and create an r.polygon(). I understand how to do the query via RethinkDB's data explorer , but I'm having trouble figuring out how to send it via JSON from the client to the server and insert it through my query there.
I basically want to do this:
r.db('places').table('locations').insert({
name: req.body.name,
bounds: r.polygon(req.body.bounds)
})
where req.body.bounds looks like this:
[long, lat],[long, lat], [long, lat]
I can't send it in as a string because then it gets read as one single input instead of three arrays. I'm sure there's a 'right in front of me' way, but I'm drawing a blank.
What's the best way to do this?
Edit: To clarify, my question is, what should my JSON look like and how should it be received on my server?
This is what RethinkDB wants in order to make a polygon:
r.polygon([lon1, lat1], [lon2, lat2], [lon3, lat3], ...) → polygon
As per the suggestion, I've added in r.args() to my code:
r.db('places').table('locations').insert({
name: req.body.name,
bounds: r.polygon(r.args(req.body.bounds))
})
Edit
Ok, I was dumb and had a typo in one of my coordinates!
Sending it as an array of arrays and wrapping it in r.args() on the server side works.
What you need is r.args to unpack the array into arguments for r.polygon. https://www.rethinkdb.com/api/javascript/args/
With assumption that req.body.bounds is:
[[long, lat],[long, lat], [long, lat]]
And you are submit a raw JSON string from client.
You first need to decode the JSON payload, and get the bounds field, wrap it with args as following:
var body = JSON.parse(req.body)
r.db('places').table('locations').insert({
name: req.body.name,
bounds: r.polygon(r.args(body.bounds))
})
If I use this URL:
https://api.xively.com/v2/feeds/65673.json?datastreams=3
Xively returns this:
{ "id":65673,
"title":"Swimming Pool",
"private":"false",
"tags":["arduino","xbee"],
"description":"Monitors swimming pool conditions",
"feed":"https://api.xively.com/v2/feeds/65673.json",
"status":"live",
"updated":"2013-08-03T22:35:27.489534Z",
"created":"2012-07-02T00:23:57.518294Z",
"creator":"https://xively.com/users/scott216",
"version":"1.0.0",
"datastreams":[{
"id":"3",
"current_value":"76.20",
"at":"2013-08-03T22:35:27.247712Z",
"max_value":"93.6","min_value":"-2845.0",
"tags":["Temp 1"],
"unit":{"symbol":"F","label":"Degrees"}
}],
"location":{
"disposition":"fixed",
"exposure":"outdoor",
"domain":"physical"
}
}
But In only want the current_value 76.20. Is there a way to add a filter or something to the URL so it only returns the current value?
I am presuming that you are not intending to use a JSON parser, as otherwise it wouldn't be a problem to get what you need as it's just parsed_json['datastreams'][0]['current_value'].
With Xively API V2 you can use CSV format, it's more close to what you want.
retrieve a feed with datastream filter as you just showed, but using CSV:
GET https://api.xively.com/v2/feeds/65673.csv?datastreams=3
3,2013-08-05T09:18:01.566388Z,59.10
retrieve a datastream itself:
GET https://api.xively.com/v2/feeds/65673/datastreams/3.csv
2013-08-05T09:18:01.566388Z,59.10
The first example only makes sense when you are to fetch more then one datastream in a single request, but you don't want all of them so you would call:
GET https://api.xively.com/v2/feeds/65673.csv?datastreams=1,2,3
If all you want is just one datastream, you should use the second example and split on comma.
I have this code.I want to have some rows in JSON,to find it Im trying to use criteria. I want render each case as json.
Example: I want the row of my table that have Name:"pepito" .if I put params.nombre, but I want this only this row in JSON how can I do that?
Im trying to do that with findbyNombre(params.nombre) but if I put some if/else with his conditions it doesnt found.
Please,can somebody help me????I have to give my code for a job and Im lost!!!
THANKS!
case "GET":
def criterios=CatalogoJson.createCriteria().list() {
if (params.nombre) {
eq('nombre', params.nombre)
// render CatalogoJson.findByNombre(params.nombre)as JSON
}
if(params.id) {
eq('id', CatalogoJson.findById(params.id))
}
}
render criterios as JSON
break
I might not have got the question correctly as to what is expected. My assumption is that, you would have either of the params (either nombre or the Id or both) available in the request. Based on that assumption you can have the criteria implemented as below. Note:- I used toInteger() as you mentioned the datatype as int, generally ids are Long in conjunction with GORM and Hibernate persistence layer.
def criterios = CatalogoJson.createCriteria().listDistinct {
if(params.id) {
idEq(params.id.toInteger())
}
if (params.nombre) {
eq('nombre', params.nombre)
}
}
render criterios as JSON
UPDATE
Ok let me try this one more time. Again if I have followed you incorrectly, let me know.
The way you are expecting to map url is not RESTful. Instead, there is one best way to implement what you are expecting in the REST service:-
Pleasant way OR I-like-it-this-way
The url mapping should look like
"/catalog/$id?"(resource: 'catalog')
//Controller Action:-
def show(){
def criterios = CatalogoJson.createCriteria().list {
if(params.id) { //check 1
idEq(params.id.toInteger())
} else if(params.name) { //check 2
eq('name', params.name)
} else if(params.year){ //check 3
eq('year', params.year)
} else if(params.others){ //check 4
eq('others', params.others)
} //so on an so forth //Can also use Switch case if you want
}
render criterios as JSON
}
Use case:-
http://mydomain.com/catalog/134 --> should set the id to 134 and check 1 will be evaluated
http://mydomain.com/catalog?name=Pep --> should set the name to Pep and check 2 will be evaluated
http://mydomain.com/catalog?year=1987 --> should set the year to params as 1987 and check 3 will be evaluated
Inference-
Use of named query parameters to itemize your parameters with respect to your need in REST service and domain. If you want to use unnamed parameters then the url mapping would look like:
"/catalog/$id/$name?/$year?/$others?"(resource: 'catalog')
The problem in this approach is that your url should look like
http://mydomain.com/catalog/134
http://mydomain.com/catalog/134/Pep
http://mydomain.com/catalog/134/Pep/1987
Your optional parameters are no more optional. Have a look at Optional Variables in URL mapping