0% found this document useful (0 votes)
15 views13 pages

First Steps Slides

This document provides a guide on creating a FastAPI application, including installation, setting up a REST API, and running the project in development mode. It emphasizes the importance of HTTP requests in controlling application flow and offers resources for further learning. Additionally, it includes demo code and links to FastAPI documentation.

Uploaded by

Nikhil Pandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views13 pages

First Steps Slides

This document provides a guide on creating a FastAPI application, including installation, setting up a REST API, and running the project in development mode. It emphasizes the importance of HTTP requests in controlling application flow and offers resources for further learning. Additionally, it includes demo code and links to FastAPI documentation.

Uploaded by

Nikhil Pandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

First Steps with FastAPI

Reindert-Jan Ekker

@rjekker www.codesensei.nl
Create a FastAPI app
- Explore
Overview - Run

Check result in browser


- REST Api
- Auto-generated documentation

Common Problems
FastAPI code execution
- Async
Demo - Start a PyCharm project
- Install FastAPI
- Create a FastAPI app
- Run
- Inspect the result
Control flow is dictated
by incoming HTTP
Requests
An operation is only called if its URL is
requested.
python -m pip install "fastapi[all]”

Install FastAPI
Extra dependencies are installed using [all]
This includes the uvicorn server
Make sure to install in an active virtual environment
from fastapi import FastAPI

app = FastAPI()

Creating a FastAPI Application Object


The app object represents our REST service
@app.get("/date")
def date():

"""Return the current date/time."""


return {'date': datetime.now()}

Add an Operation
URLs should start with a slash
There is no connection between URL and function name
When a GET request comes in for /date, the function will be called
from fastapi import FastAPI

app = FastAPI()

Creating a FastAPI Application Object


The app object represents our REST service
@app.get("/date")
def date():

"""Return the current date/time."""


return {'date': datetime.now()}

Add an Operation
URLs should start with a slash
There is no connection between URL and function name
When a GET request comes in for /date, the function will be called
fastapi dev my_project.py

Running FastAPI Project


my_project.py is the name of the python file containing the application object
dev means to run in development mode: auto-reload changes in the code
In production you should use “run” instead of “dev”
Resources

FastAPI documentation: https://fastapi.tiangolo.com/

Demo code: github.com/codesensei-courses/fastapi_foundations


Summary Install FastAPI
Create and run a FastAPI app
Autogenerated documentation
Common Problems
FastAPI code execution
Up Next:
Serving Data with FastAPI

You might also like