API Integration in Python – Real Python | Restful api post python
Inthissection,you’lllookatthreepopularframeworksforbuildingRESTAPIsinPython.Eachframeworkhasprosandcons,soyou’llhavetoevaluatewhichworksbestforyourneeds.Tothisend,inthenextsections,you’lllookataRESTAPIineachframework.AlltheexampleswillbeforasimilarAPIthatmanagesacollectionofcountries.Thefieldsname,capital,andareastoredataaboutaspecificcountrysomewhereintheworld.Mostofthetime,datasentfromaRESTAPIcomesfromadatabase.Connectingtoadatabase[1]isbeyondthescopeofthistutorial.Fortheexamplesbelow,you’...
In this section, you’ll look at three popular frameworks for building REST APIs in Python. Each framework has pros and cons, so you’ll have to evaluate which works best for your needs. To this end, in the next sections, you’ll look at a REST API in each framework. All the examples will be for a similar API that manages a collection of countries.
The fields name, capital, and area store data about a specific country somewhere in the world.
Most of the time, data sent from a REST API comes from a database. Connecting to a database[1] is beyond the scope of this tutorial. For the examples below, you’ll store your data in a Python list. The exception to this is the Django REST framework example, which runs off the SQLite database that Django creates.
To keep things consistent, you’ll use countries as your main endpoint for all three frameworks. You’ll also use JSON as your data format for all three frameworks.
Now that you’ve got the background for the API, you ...