user1579937
user1579937

Reputation: 77

Tastypie Single Resource

I am writing an API with tastypie and I would like an API endpoint to only return 1 instance of a resource. The way I would like this to work is to enforce a parameter such as an ID.

For example, I would like /api/v1/users to return an error or a statement that says a required parameter is not there. However, I would like /api/v1/user/:id to simple return the id of that User.

Maybe I'm not searching up the right thing but I can't find any documentation on how to do this.

Upvotes: 1

Views: 413

Answers (1)

Mark Shust at M.academy
Mark Shust at M.academy

Reputation: 6429

You can use the following within your Class Meta

    list_allowed_methods = []
    detail_allowed_methods = ['get']

This will disable listing values but allow them when an id is supplied.

Upvotes: 4

Related Questions