ngrest post request query

76 views
Skip to first unread message

Kumar

unread,
Oct 14, 2017, 1:28:10 AM10/14/17
to ngrest
 Hi,

Deployed ngrest under nginx. I have create two services(add,get)

santhosh@santhosh-Lenovo-U310:
~$ ls restapi/
add  CMakeLists.txt  get

copied the lib to following location
--------------------------------
santhosh@santhosh-Lenovo-U310:~$ ls -l /opt/ngrest/services/
total 652
-rwxr-xr-x 1 root root 310344 Oct 13 11:30 add.so
-rwxr-xr-x 1 root root 353232 Oct 13 11:30 get.so

And added location in site-enabled config
--------------------------------
location ~ /(ngrest|restapi|get|getAll) {
    ngrest /opt/ngrest/services;
}

location ~ /(ngrest|restapi|add|addRecord) {
    ngrest /opt/ngrest/services;
}

loaded ngrest module and added included site-enabled in nginx.conf
--------------------------------
load_module /home/santhosh/.ngrest/ngrest-build/deploy/share/ngrest/modules/nginx/mod_ngrest.so;

include /etc/nginx/sites-enabled/*;

Able to do get service from browser

http://localhost/get/getAll

{
"result": [
  {
"empId": 200,
"empName": "jai",
"empOrg": "aticara"
},
  {
"empId": 100,
"empName": "madhu",
"empOrg": "isoke"
},
  {
"empId": 400,
"empName": "mohan",
"empOrg": "isoke"
},
  {
"empId": 300,
"empName": "santhosh",
"empOrg": "aticara“ "
}
],
}

Similarly not able to do for add(POST) service

http://localhost/add/addRecord?id=123&name=skumar&org=aticara
getting below error from browser.

The requested URL can't be reached

in ngrest log

------------------------------------------

santhosh-Lenovo-U310:/tmp$ tail -f ngrest_3381.log
D/14-10-2017 10:54:05.824 ServiceDispatcher.cpp:473 dispatchMessage: inside else lastNamedNode
D/14-10-2017 10:54:05.824 ServiceDispatcher.cpp:509 dispatchMessage: inside if engine runphase
D/14-10-2017 10:54:05.824 ServiceDispatcher.cpp:513 dispatchMessage: Invoking service operation 2--get/getAll
D/14-10-2017 10:54:05.824 ServiceDispatcher.cpp:517 dispatchMessage: inside invoke
D/14-10-2017 10:54:05.824 get.cpp:9 getAll: Entered get::getAll method
D/14-10-2017 10:54:06.466 get.cpp:106 getAll: Ended get::getAll method
D/14-10-2017 10:54:19.999 ServiceDispatcher.cpp:360 dispatchMessage: Dispatching message /add/addRecord?id=123&name=skumar&org=aticara
D/14-10-2017 10:54:19.999 ServiceDispatcher.cpp:372 dispatchMessage: Santhosh: method - 1 1
D/14-10-2017 10:54:19.999 ServiceDispatcher.cpp:399 dispatchMessage: Santhosh: inside paramResource base path size 0
D/14-10-2017 10:54:19.999 ServiceDispatcher.cpp:402 dispatchMessage: inside inner if paramResource : 2

For reference i have added my source code. please advice how to resolve this.

Thanks,
restapi.tar.gz

Dmitry Utkin

unread,
Oct 21, 2017, 5:22:45 PM10/21/17
to ngrest
Hello,

The argument names in your service and query parameters do not match.

you should either of:

1) rename your arguments to match parameters:


http://localhost/add/addRecord?id=123&name=skumar&org=aticara

int addRecord(const int id, const std::string name, const std::string org);


2) match parameters using location binding:

// *location: ?id={eId}&name={eName}&org={eOrg}



суббота, 14 октября 2017 г., 8:28:10 UTC+3 пользователь Kumar написал:

Dmitry Utkin

unread,
Oct 22, 2017, 4:22:16 AM10/22/17
to ngrest
Also, you should remove or update this line

    // *location: /{text}

because of it binds to invalid location


воскресенье, 22 октября 2017 г., 0:22:45 UTC+3 пользователь Dmitry Utkin написал:

Kumar

unread,
Nov 29, 2017, 1:52:38 PM11/29/17
to ngrest
Thanks for your information.
Reply all
Reply to author
Forward
0 new messages