I'm using Pyramid with Cornice to create an API for a Backbone.js application to consume. My current code is working perfectly for GET
and POST
requests, but it is returning 404 errors when it receives PUT
requests. I believe that this is because Backbone sends them as http://example.com/api/clients/ID
, where ID
is the id number of the object in question.
My Cornice setup code is:
clients = Service(name='clients', path='/api/clients', description="Clients")
@clients.get()
def get_clients(request):
...
@clients.post()
def create_client(request):
...
@clients.put()
def update_client(request):
...
It seems that Cornice only registers the path /api/clients
and not /api/clients/{id}
. How can I make it match both?
The documentation gives an example of a service that has both an individual path (
/users/{id}
) and an object path (/users
). Would this work for you ?A quick glance at the code for the
resource
decorator shows that it mainly creates twoService
: one for the object and one for the collection. Your problem can probably be solved by adding anotherService
: