loentar/ngrest

May u be able to extend the rest api to cover ajax as well

Closed this issue · 8 comments

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.

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).

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

https://github.com/loentar/ngrest/wiki/ngrest-script

Got it! Now works nicely. Thanks for your quick response.