Code Monkey home page Code Monkey logo

rest-apis-flask-python's Introduction

REST APIs with Flask and Python

REST APIs with Flask and Python (Udemy banner image)


๐Ÿ’ก A full course to teach you how to use Flask and Python to make REST APIs using multiple Flask extensions and PostgreSQL.

Getting started

Enrol in the course by going to this link.

Then you can come back here to download the repository. This repository contains the code that we develop in each section of the course.

If you are familiar with Git, you can use Git to download it. Otherwise, you can download it as a zip file:

Download repo as a zip file

Next, start taking the course at the beginning! You can use the downloaded code files to support you while you go through the course.

I also strongly recommend you code while you take the course. A good strategy is:

  1. Watch the video intently, optionally while taking notes.
  2. Watch again, more quickly, while typing the code together with me.
  3. Once you're done with the video, play about with the code. Make changes, break things, then fix them, and try to thoroughly understand everything the code does.

If you do this for the entire course, I guarantee you will learn how to make REST APIs using Flask and Python well and quickly. You'll still be using Google and searching for stuff every day, but so does everyone else!

Section 2: A Full Python Refresher

This section (only available on Udemy) helps programmers who are new to Python get acquainted with the language. It is not a complete-beginner Python course!

Section 3: Your first REST API

The code in this section includes a simple Flask app that accepts and returns JSON data.

Section 4: Docker

Introduction to Docker to run your REST APIs. We talk about images, containers, and how to run applications.

Section 5: Flask-Smorest

We introduce the Flask-Smorest extension, a library that greatly simplifies writing REST APIs using Flask. It also provides things like automated documentation generation.

Section 6: Flask-SQLAlchemy

The code in this section extends the previous section by replacing the data storage in Python lists with SQLAlchemy, an ORM (Object-Relational Mapping which simplifies connecting to and interacting with a database.

Section 7: Many-to-many relationships

In this section we talk about many-to-many relationships using SQLAlchemy.

Section 8: Authentication with Flask-JWT-Extended

Learn how to perform user authentication using JWTs and the Flask-JWT-Extended library. Here we talk about access token JWTs, as well as refresh tokens, JWT claims, blocklists, password hashing, and more.

Section 9: Flask-Migrate

After deploying your apps, making changes to the database can be really tricky because you have to log in to the database server and manually update the database tables using SQL commands.

Flask-Migrate and the Alembic libraries simplify this job by creating migration scripts.

Section 10: Git Crash Course

A quick and intense course on Git and GitHub for code sharing.

Section 11: Deploying to Render.com

Learn how to get your code running in the cloud and make it publicly accessible. In this section we use Render.com for deployments and we also deploy a PostgreSQL database.

rest-apis-flask-python's People

Contributors

andrew-harding-gh avatar antoniovmonge avatar cristianoyl avatar davimiku avatar dependabot[bot] avatar glmeece avatar jslvtr avatar justin-f-reeves avatar lukamilivojevic avatar lus24 avatar petarpetarpetar avatar pfabri avatar reillychase avatar sattamjh avatar senarclens avatar teclado-jennifer avatar teksaver avatar veeshostak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rest-apis-flask-python's Issues

UnitTests, JWT

Library flask_jwt is outdated. (Last commit was 3 years ago)

ch11 step 1 render.com does not create the tables

Running the app on render.com triggers the following

OperationalError
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: stores
[SQL: SELECT stores.id AS stores_id, stores.name AS stores_name
FROM stores]
(Background on this error at: https://sqlalche.me/e/20/e3q8)

Seems like the data.db is not created when running the app

/auth error

in chapter 4 authentication and logging part2:
I got error when sending GET /auth

<!doctype html>
<html lang=en>
<title>405 Method Not Allowed</title>
<h1>Method Not Allowed</h1>
<p>The method is not allowed for the requested URL.</p>

circular dependency section 6

Hi,

In section 6 of your course, you spoke about circular dependency, but I don't understand why.
I try to put 'from db import db' at the top of the app.py file and it work without errors.

Could you explain brieffly, in which case this circular dependency happen ?

thanks,

Mickael

500 error when creating new Item and no Store exists

When testing in Digital Ocean it showed a 500 error when I tried to create a new item with store id 1 without creating a store before sending the request.

Maybe it would be nice to check the existence of a store and show a more informative message.

Also, add to the course a note about this happening.

problems while doplying api in digital-ocean platform using mysql as database

in addition nginx in showed msg in the broswer 404 Not Found
i still google to fix them........and please if you add tut how to use MySQL instead of PostgreSQL but also you can help..thanks in advance sir Jose

*** Starting uWSGI 2.0.16 (64bit) on [Thu Feb 22 11:39:09 2018] ***
compiled with version: 5.4.0 20160609 on 22 February 2018 09:17:09
os: Linux-4.4.0-112-generic #135-Ubuntu SMP Fri Jan 19 11:48:36 UTC 2018
nodename: Flask-Api-Test
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /
detected binary path: /var/www/html/items-rest/venv/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
dropping root privileges as early as possible
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
your processes number limit is 3913
your memory page size is 4096 bytes
*** WARNING: you have enabled harakiri without post buffering. Slow upload could be rejected on post-unbuffered webservers ***
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /var/www/html/items-rest/socket.sock fd 3
dropping root privileges after socket binding
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
Python version: 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609]
Set PythonHome to /var/www/html/items-rest/venv
Python main interpreter initialized at 0x2066f80
dropping root privileges after plugin initialization
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 1315008 bytes (1284 KB) for 64 cores
*** Operational MODE: preforking+threaded ***
added /var/www/html/items-rest/ to pythonpath.

  • Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
  • Restarting with stat
    *** has_emperor mode detected (fd: 6) ***
    unable to load configuration from uwsgi

Item PUT HTTP response - correction proposal

def put(self, name):
data = Item.parser.parse_args()
item = ItemModel.find_by_name(name)
if item:
item.price = data['price']
else:
item = ItemModel(name, **data)
item.save_to_db()
return item.json()

Hi,
In Lec99, the HTTP response of PUT is not fully correctly dealt with. According to this: https://httpwg.org/specs/rfc7231.html, PUT should return 201, when new resource has been created.
(Also, added error handling similarly to the post() method)
So, I think implementation of put() should be appended with the HTTP response code handling, like this:

    def put(self, name):
        data = Item.parser.parse_args()
        item = ItemModel.find_by_name(name)

        # if item with name doesn't exist, we create it
        if item is None:
            item = ItemModel(name, **data)
            http_status_code = 200
        else:
            item.price = data["price"]
            http_status_code = 201

        try:
            item.save_to_db()
        except:
            return {"message": "An error occurred upserting the item."}, 500

        return item.json(), http_status_code

Best,
Csb

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.