Hello
Having limited success with the REST server, if somebody could assist that would be great.
I have installed and tested the folloing URL and it works as expected.
REQUEST
htp://localhost/points/services/rest/node/1
RESPONSE
1product111259554608125955460821000011Product 1Product 1Product 112595546081admina:0:{}123420.0000020.0000020.000000lb000in115beefe1aab7634836f0481f378af15dd0112595546080http://localhost/points/services/rest/node/1
In order to test things out for creating our own service we created the echo service. This works fine for xml_rpc calls,
but when we attempt to access this service using REST we are runnining into a 404 problem.
REQUEST
http://localhost/points/services/rest/service_echo
RESPONSE
404 Not found: could not find controller localhost
I have installed the latest and greatest dev versions of DEV services module and rest server (http://github.com/hugowetterberg/rest_server)
If somebody could advise that would be greatly appreciated.
Development environment is on a mac using XAMP, latest stable drupal etc.
Thanks
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | Screen shot 2010-11-03 at 5.32.14 PM.png | 48.59 KB | jrigby |
Comments
Comment #1
Hugo Wetterberg commentedHi could you please upload the echo service so that I might debug it, other than that there seems to be some strange path<->domain mixup as it's looking for the controller localhost.
I'll try to reproduce this so that we can get a fix.
Cheers
Hugo
Comment #2
Openlogic commentedI'm experiencing this same issue while trying to construct a custom service and call it using the REST server.
I always seem to get a 404 controller not found. Is there somewhere I can find samples of a simple custom service (non-node specific) that works with REST_SERVER? echo would be perfect
Thanks
Faisal
Comment #3
ehodul commentedI have exactly the same question - how to call custom service (e.g. myService.hello). Please give us an example URL.
How to call for example system.connect service?
Comment #4
ngstigator commentedsubscribe
Comment #5
karma.code commentedsubscribe
Comment #6
voxpelli commentedCalling a regular service like myService.hello with REST Server seems like it should be something like:
POST /services/rest/service_myService/hello
Can you try that?
You can also try creating resources instead of services - that will be the standard way to create implementations for Services 3.x
EDIT: Missed a part of the URL at first - fixed it.
Comment #7
jrigby commentedThis doesn't work for me. The node example works fine:
http://localhost/services/rest/node/1
returns the XML of the requested node.
I have a custom service defined with:
The service shows up fine in the services admin and when I submit through the web test it works fine, triggering mplayer_integration_get_tokens() with the passed arguments (see attached image). How do I call this service? I've tried:
And I get 404 Not found: could not find controller with both.
Why does http://localhost/services/rest/node/1 work when 'node' is not one of the defined services? How does it know to trigger node.get?
Does anyone have a working example of the REST Server working with a custom service?
Comment #8
voxpelli commentedThe node is a resource and not a service - resources are easier for the servers to interpret.
Have you tried making a real POST request (not using the Services browser or anything) to /services/rest/service_mplayer/get as I mentioned in #6?
Comment #9
jrigby commentedPost does work. There definitely seems to be a problem with get method. I haven't tried any of the other methods yet.
I noticed one thing that seems odd, though changing didn't seem to do anything. The following code:
Should $method='POST' really be $method=='POST' (= vs. ==) otherwise this is always setting it to POST in the condition which is usually not the desired action.
Comment #10
voxpelli commentedThere seems to be a bug there yes - but it's not affecting your code. If I remember correctly then old services are only allowed to do POST-requests since that's the only HTTP-method that can be trusted to run random function calls.
If you want to be able to do GET, PUT and DELETES you need to create a resource instead of a service I believe.
Comment #11
barnettech commentedI'm seeing the same problem with the lates Drupal 7 and services 3.x It cannot find the controller using rest. It is a custom resource I created.
UPDATE: nevermind I find the bug in my code. The code specifically looks for the words 'retrieve', 'update', 'delete', 'index' I had thought that was a custom action to define and I named it something different. I stubbled upon these lines in services.module of the Drupal 7 services module.
(line 350 or so)
foreach (array('create', 'retrieve', 'update', 'delete', 'index') as $op) {
if (isset($res[$op])) {
$controllers[] = $resource_name . '.' . $op;
}
}
Anyhow I always hope to help the next poor soul that runs into the same problem.
Comment #12
arsura2 commented@barnettech - "Anyhow I always hope to help the next poor soul that runs into the same problem.",
You just found that poor soul in me. I've pulled my hair for hours trying to figure out what went wrong and finally saw this. As soon as I change the method names in my resource to Create, retrieve etc. - voila it works.
Thanks for the fix.
Comment #13
fleggbert commented@barnettech: I can't seem to get it working. How do you exactly implement the basic CRUD resources? And shouldn't it work anyway, since in the next lines in services.module the "extended operations" are handled without depending on the result of the default CRUD foreach loop?
EDIT: I am using D7...any updates there?
Comment #14
randa.elayan commentedHi,
I also get this
Exception is: exception 'ServicesException' with message 'Unsupported request content type application/x-www-form-urlencoded' in /home/yousrvc/public_html/cms/sites/all/modules/services/services.runtime.inc:330 Stack trace: #0 /home/yousrvc/public_html/cms/sites/all/modules/services/servers/rest_server/includes/RESTServer.inc(272): services_error() #1 /home/yousrvc/public_html/cms/sites/all/modules/services/servers/rest_server/includes/RESTServer.inc(201): RESTServer->parseRequest('Unsupported req...', 406) #2 /home/yousrvc/public_html/cms/sites/all/modules/services/servers/rest_server/includes/RESTServer.inc(88): RESTServer->getControllerArguments('POST', Array) #3 /home/yousrvc/public_html/cms/sites/all/modules/services/servers/rest_server/rest_server.module(34): RESTServer->handle(Array, Array, 'POST', Array) #4 /home/yousrvc/public_html/cms/sites/all/modules/services/services.module(205): rest_server_server('system/connect', 'mservice') #5 /home/yousrvc/public_html/cms/includes/menu.inc(516): services_endpoint_callback() #6 /home/yousrvc/public_html/cms/index.php(21): menu_execute_active_handler() #7 {main}
And I have no idea why!
Comment #15
selvamkf commentedEnsure you have enabled request parsing for application/x-www-form-urlencoded at admin/structure/services/list/NAME/server
Comment #16
halthFor the folks getting this error from services 7.x-3.3, check this issue out: http://drupal.org/node/1917432
Hope it can help someone out there!
Comment #17
zarexogre commentedSolved: http://popthestash.com/2013/10/14/fixed-create-a-custom-service-resource...