API Development With Flask for Beginners

Get started building back-end services with Python

Peter Ayeni
Apr 12, 2020 · 9 min read
Image for post
Image for post
Image Source: https://www.endivesoftware.com

Background

Technologies

Side note

Definitions

API definition

JSON definition

HTTP definition

GET

POST

PUT

DELETE

PATCH

What We Are Going to Build

Getting Started

mkdir aa-api
cd aa-api

Install Pipenv

pip install --user pipenv

Install Flask

pipenv install flask
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
flask = "*"
[requires]
python_version = "3.8"
Image for post
Image for post

Running Our App

➜  aa-api pipenv shell 
Launching subshell in virtual environment…
. /Users/peterayeni/.local/share/virtualenvs/aa-api-9L89IsJh/bin/activate
➜ aa-api . /Users/peterayeni/.local/share/virtualenvs/aa-api-9L89IsJh/bin/activate
(aa-api) ➜ aa-api
(aa-api) ➜  aa-api python app.py
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Image for post
Image for post

Bus Data

Number Plate
Manufacturer
Model
Year
Capacity
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

Get one bus

Image for post
Image for post
Image for post
Image for post

Add a new bus

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

Update and delete

Image for post
Image for post
Image for post
Image for post

Full Code

Image for post
Image for post

Better Programming

Advice for programmers.

Sign up for The Best of Better Programming

By Better Programming

A weekly newsletter sent every Friday with the best articles we published that week. Code tutorials, advice, career opportunities, and more! Take a look

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Peter Ayeni

Written by

I change the world by helping people to get started in Tech and Social Entrepreneurship.

Better Programming

Advice for programmers.

Peter Ayeni

Written by

I change the world by helping people to get started in Tech and Social Entrepreneurship.

Better Programming

Advice for programmers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app