r/learnpython • • Sep 04 '19

Wrote my first API

I would love any feedback. The API simply returns homebrewing calculations. I know there still a lot to do. Brew Numbers API

Github Repo

425 Upvotes

44 comments sorted by

View all comments

10

u/Sebass13 Sep 04 '19

I'd personally recommend using URL parameters over URL routing to pass in the parameters to the endpoints; it's what they are there for, and it is better supported by libraries. If you used URL parameters, here's what a request to your URL would look like with requests:

requests.get("http://18.216.248.93/carbonation/howmuchsugar/", 
             params={"temp":65, "co2volume":33.0, "beervolume":10.0})

That is a lot more intuitive than what it would look like with URL routing.

5

u/bmw2621 Sep 04 '19

In reading I saw curl has the same option. I need to figure out how to receive parameter. This would probably make error handling easier.

Thanks for the feedback

2

u/gopherhole22 Sep 04 '19

I would second this. If somebody is using your api, the order of the numbers is not so intuitive. On the api end you should be able to access parameters passed as either req.body for POST and req.params or req.query for GET calls. Typically you can structure your api on what format you like. Either api.com/:id which should be passed api.com/id/233...... or as params in a url query string so api.com/id=123. I prefer the query string as I think it is more flexible to handle on the backend.