V
V
Vladimir2015-09-20 20:25:27
JSON
Vladimir, 2015-09-20 20:25:27

Is it possible in REST services to send a request to the server as a JSON document?

How to send a request to get a document to a service in a REST service?
It is clear that I can parse my document into pieces for a GET request and send it
to
/query/?field1=1&field2=2&field3['fdgfd']=3
But, it would be much nicer to work with the request if I worked with it as a document

{
field1:1,
field2:2,
field3: {
'fdgfd':3
}
}

Of course, I can send the document by POST, but POST means saving the document in REST

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2015-09-20
Protko @Fesor

/api/v1/some_resources?json=%7B%0Afield1%3A1%2C%0Afield2%3A2%2C%0Afield3%3A%20%7B%0A%27fdgfd%27%3A3%0A%7D%0A%7D

but it's a stick.
Well, in fact, yes, but if necessary, then you can, anyway, the chances that you will get a clean restful tend to zero.

T
Timur Shemsedinov, 2015-09-22
@MarcusAurelius

var data = { field1: 1, field2: 2, field 3: { fdgfd: 3 } };
varxhr = new XMLHttpRequest();
xhr.open('POST', '/api/method', true);
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
xhr.send(json.stringify(data));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question