From the course: Building RESTful APIs with Flask

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Retrieving a single planet's details

Retrieving a single planet's details

From the course: Building RESTful APIs with Flask

Start my 1-month free trial

Retrieving a single planet's details

- [Instructor] I've heard it said that the devil is in the details. I don't know if that's true, but I do know that showing a detail view in an API is definitely something we want to do. We've already built a list view that lists all the planets. Each planet has a planet ID field that's assigned by the databases and auto-incrementing primary key. We can use that planet ID to retrieve the details for a given planet. I'm going to add a route right below the retrieve_password route. So I'll type in app.route, and I'll call it/planet_details/, and I'm going to be passing in that ID from the database so I'm going to make a variable rule here, it's going to be an integer, and I'm going to call it planet_id, and I'm going to limit this to just get requests. Now I'll go ahead and add my method signature. So def planet_details, we're going to pass in planet_id of type integer. SQLAlchemy makes this operation fairly straightforward, I'll just create a variable called planet to hold my result…

Contents