Closed iot-cloud closed 6 years ago
I don't understand your question. ngrest is designed to do AJAX. You have to request web resource and get result as JSON (or other format).
Hi Dimtry,
I have tried to use AJAX from ExtJS to NGREST before.
NGREST does not seem throw an exception in regarding the incorrect Context-Type.
Let me work on an example to capture the error and will let you know ASAP.
Regards, Henry
On 6 Nov 2017, at 6:39 pm, Dmitry notifications@github.com wrote:
I don't understand your question. ngrest is designed to do AJAX. You have to request web resource and get result as JSON (or other format).
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/loentar/ngrest/issues/45#issuecomment-342068762, or mute the thread https://github.com/notifications/unsubscribe-auth/Abe5YQOm_-LFgJfBHrm0FEzRDGk-aB6Vks5szreugaJpZM4QSpZK.
As I remember there was a problem with ExtJS.
If you pass wrong Content-Type to ngrest it will respond with Can't handle content type: xxxx
@loentar I am running examples/crud and need to use get
(read), put
(update) with requests
in python. Get was successful, however, put
was not. It throws Can't handle content type:***
. I have tried different types and non of them are supported.
Can't handle content type: text/plain
Can't handle content type: text/html
Can't handle content type: text
What content-type should I set when trying put
and post
?
headers={"content-type": "text/plain"}
myobj = {'1': 'somevalue'}
x = requests.put(url, headers=headers, data = myobj)
print(x.text)
You should use standard application/json
content type.
I see. I just tried that:
headers={"content-type": "application/json"}
myobj = json.dumps({'1': 'somevalue'})
x = requests.put(url, headers=headers, data = myobj)
print(x.text)
and it shows:
Failed to get child data is missing
I can confirm that the object {1} already exists containing some other value. My goal is to update this value and then post
new object-value pair. I also tried non-json style myobj = {'rover/camera': 'somevalue'}
which throws Unexpected symbol: [r]
.
Where am I doing wrong here ?
As mentioned in example your request should look like this
example of request:
http://server:port/ngrest/examples/data/1
-- body -----------------------
{
"data": "Object #1"
}
in your case "data" element is missing (you have "1" instead)
For debug start ngrest like this:
NGREST_LOG_LEVEL=TRACE NGREST_LOG_VERBOSITY=ALL ngrest
Got it! Now works nicely. Thanks for your quick response.
Hi ngrest gatekeeper
When you are programming using the web interface, rest and ajax are supported.
Is there a possibility to extend the current ngrest to support ajax as well.
What does it take to extend the current ngrest to support ajax? Any pointer is much appreciate?
Thanks and Regards.