URL parameter vs post form data - rest

URL parameter or post form data; which is more computationally efficient for a backend API to query?
example:
GET : user/:id
POST: user/ { "id": "some_id" }

Related

How can I send an conditional GET method to elasticearch from postman?

I have a GET request with it's query body as shown below:
GET /courses/_search
{
"query": {
"bool": {
"must": [
{"match": {"teacher.keyword": "Andrew Ng"}}
]
}
}
}
In Postman, GET requests can not have a 'body'. so how can I send this request to the elasticsearch? How should I specify this neseted structure of the body in the request?
Use POST instead 😃
Elasticsearch is a bit more permissive and supports both GET and POST to send a request with a payload.

JSON server - Is it possible to update an object id?

Here is my db.json :
{
"users": [
{
"id": "1"
"name": "John"
}
]
}
I'd like to be able to update the user id by sending a PUT request on the existing user. But the following does not work:
Request URL :
PUT /users/1
with body:
{
"id": "2"
"name": "John"
}
Is there a way to update an object id?
If you are using PUT request means ,the request URL should be like this "PUT/users/1" .
Refer below mentioned image.
I'm using postman to send put request
This does not seem to be possible, as said in documentation:
Id values are not mutable. Any id value in the body of your PUT or
PATCH request will be ignored. Only a value set in a POST request will
be respected, but only if not already taken.

Talend read JSON data from tRESTRequest

I am trying to learn Talend.
Scenario:
I have to create a REST endpoint (i am using tRESTRequest) which takes a POST request at http://localhost:8086/emp/create and accepts below json and prints each json field and sends a sample json response containing only name field.
How can I do so ?
How to read the json data into a java component like tJava?
Structure:
{
"emp" :
[
{
"id":"123",
"name": "testemp1"
},
{
"id":"456",
"name": "testemp2"
}
]
}
Expected Response:
{
"emp" :
[
{
"name": "testemp1"
},
{
"name": "testemp2"
}
]
}
I am using tRESTRequest -> tExtractJSONFields -> tRESTResponse.
For looping on the right elements and parsing the contents, please see my answer JSON Deserialization on Talend
I did not understand the second question. When deserializing JSON, the data will already be available in the usual row format for processing further. Beginner tutorials will show you the standard structure. The component tJava is - of course - an exception to that rule. Handling data is different in this component and not neccessarily row based.
Talend has an excellent knowledge base for components and examples, see https://help.talend.com/

Meteor: Difference between request.query and request.body in restFul API

while using restFul Api in meteor, we return two request methods request.body and request.query for get and post methods:
Utility = {
getRequestContents: function(request) {
switch (request.method) {
case "GET":
return request.query;
case "POST":
return request.body;
}
},
But I am not getting the difference between the two.
The terminology comes from HTTP. HTTP GET requests are made to get or query something, that is why they don't have a "body", but a "query" string. POST has a body (the thing that should be POSTed), but it does not (usually) have a query.
Normally the two have different purposes and it is actually a questionable idea to mix them into a generic "content" term.

How to modify ajax response before jsTree creation?

How can I modify ajax response before jsTree creation? I would like to access each node ID and add prefix to it. On jsTree page the only clue is this: the function will receive two arguments - the node being loaded & a function". I need to do that before the tree is actually created, to avoid duplicate ID in the document.
"json_data" : {
"ajax" : {
"type": "GET",
"url" : "tree.json"
},
"data" : function(node, func){
//how to use that?
}}
I have expected to get JSON data here, modify it and return? But this will explode.
I have successfully manipulated data using the success callback in the instantiation of the jsTree. In my case, I am parsing XML data returned as JSON from a .NET webmethod. It should work for your case in a similar manner.
"ajax": {
"type": "GET"
"url": "tree.json",
"success": function (x) {
//manipulate string x to change id's here
return x;
}, ...
Another method is to use the "complete" callback function to manipulate the jsTree in its final form. I don't recommend it in your case of duplicate id's, however.