RESTful APIs in Python. What are RESTful APIs and ... | Restful api post python
We’llbeimplementingasinglecasescenariowhichmakesupformostscenariosofGETrequests.Theimportsimportjsonimportrequestsimporturllib.parseSomeGETrequestsaremadeupofendpointsthathavepathparameterswhicharen’toptionalandverymuchapartoftheendpoint,e.g.-/volunteer/{volunteerID}/badge/{badgeID}volunteerIDandbadgeIDneedtobepassedintothecompleteURLsoastocompletetheGETrequest.Thisiswherewemakeuseofurllib.parse.
We’ll be implementing a single case scenario which makes up for most scenarios of GET requests.
The importsimport jsonimport requestsimport urllib.parseSome GET requests are made up of endpoints that have path parameters which aren’t optional and very much a part of the endpoint, e.g.- /volunteer/{volunteerID}/badge/{badgeID}
volunteerID and badgeID need to be passed into the complete URL so as to complete the GET request.
This is where we make use of urllib.parse.