Planets and Webhooks: a simple Flask app

As a Developer Advocate for an API company, I spend a lot of time talking about APIs and webhooks and HTTP in general. Recently I've been focussing on HTTP tools, but I really wanted a very simple example API that I could use that would return JSON but really let me focus on the tools, not the API. So I created a "Planets and Webhooks" API with a couple of GET endpoints to return JSON data, and another endpoint to receive and log incoming webhook data.

Planets Flask App

The project is on GitHub: https://github.com/lornajane/flask-planets-and-webhooks so you can also grab it yourself to use when testing out any of the HTTP tools or getting to know webhooks that I covered in my talk (this probably makes more sense if you've seen one of my HTTP talks/streams, but hopefully still can be useful by itself).

It very simply returns a little bit of info about a planet. For example:

$ curl http://localhost:5000/planets/5
{"name": "Jupiter", "position": 5, "moons": 79}

You can use it to check out how different HTTP clients (curl, httpie and friends) handle JSON, or how tools like jq or fx can help.

The repo also includes some of the tools I usually mention: https://github.com/lornajane/flask-planets-and-webhooks/#http-tools.

Debugging Webhooks

Sometimes it is useful to have an endpoint that can receive and correctly acknowledge incoming webhooks without doing a whole lot else. This application has a simple GET/POST parameter logger on the /webhook endpoint. You can use Ngrok to allow an external webhook service such as Zapier to access your local running flask app.

Fun With HTTP

Sharing the code I used in my demo is mostly useful for people who saw the demo but if it's useful to you too, then great! I'm not the world's finest python developer (yet) but I had fun building and using this application so let me know if you do too?


Also published on Medium.

Leave a Reply

Please use [code] and [/code] around any source code you wish to share.

This site uses Akismet to reduce spam. Learn how your comment data is processed.