How this differs from a website
A website returns pages for a person. A service returns data for another program — usually as JSON.
Such services are everywhere: a mobile app talks to a server, an interface loads data into a page, one system talks to another.
FastAPI suits beginners because it forces you to describe your data strictly and turns that description into documentation for free.
Step 1. Installation
python -m venv .venv
source .venv/bin/activate
pip install fastapi uvicorn
The second is the server that will run your service.
Step 2. A first handler
Create a file with an application and one handler that answers the root address and returns a dictionary.
Run it:
uvicorn main:app --reload
The reload flag means the service restarts itself when the file changes. It saves a lot of time.
Open the address in a browser and you'll see the response as data.
Step 3. Automatic documentation
Append the documentation path to the address and you'll get a page listing every handler, each callable straight from the browser.
You didn't write it. FastAPI assembled the documentation from your code.
That isn't decoration: when you hand the service to someone, this page removes half their questions. And it looks good at an interview.
Step 4. Describing data
Describe the shape of incoming data as a separate class: which fields, of what types, which are required.
Now a request with bad data gets a clear error saying exactly what's wrong. You don't write those checks by hand.
That's the main difference from simpler frameworks and the reason FastAPI is worth trying: strict data description saves time and catches mistakes early.
Step 5. Storage
Add a database. For a learning project simple file storage is enough; for something more serious, a proper database.
Write handlers for the four basic actions: list, fetch one, create, delete.
Step 6. Deployment
Deploy on any free platform. From that moment your service is usable behind a link that you can give to anyone.
What to show in a portfolio
A service with several handlers, described data, error handling and automatic documentation is already a decent learning project.
Especially with a simple interface that consumes it: then it's clear you understand both sides.
Common beginner mistakes
Returning different shapes for success and failure without status codes. The program calling you needs a clear signal of whether it worked.
Not validating incoming data. With FastAPI that's nearly free — it would be a shame not to.
Putting keys and passwords in the code. Move them to environment variables; that's the first thing people check in a repository.
Хватит читать — пора делать
На CohortX можно найти команду под пет-проект и получить тот самый опыт, о котором спрашивают на собеседовании.
Похожие статьи
- FastAPI: первый сервис за вечерЧто такое сервис для программ, как написать первый за вечер и почему автоматическая документация экономит время.
- Django for beginners: a first project step by stepFrom installation to a working list with an admin panel — the steps, and what each one means.
- Django для начинающих: первый проект по шагамОт установки до работающего списка записей с панелью управления — что делать по шагам и что означает каждый шаг.