Skip to content

Commit 99e1e90

Browse files
adding a dummy fastapi app for now
1 parent b821588 commit 99e1e90

File tree

5 files changed

+136
-3
lines changed

5 files changed

+136
-3
lines changed

backend/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM python:3.13.3-slim
2+
3+
WORKDIR /app
4+
5+
COPY Pipfile Pipfile.lock ./
6+
COPY app ./app
7+
8+
RUN pip install --no-cache-dir pipenv
9+
10+
ENV PIPENV_VENV_IN_PROJECT=1
11+
12+
RUN pipenv install --dev
13+
14+
EXPOSE 8000
15+
16+
CMD ["pipenv", "run", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]

backend/Pipfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ name = "pypi"
55

66
[packages]
77
fastapi = {extras = ["standard"], version = "*"}
8+
9+
[dev-packages]
10+
black = "*"

backend/Pipfile.lock

Lines changed: 72 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
![FastAPI](https://img.shields.io/badge/FastAPI-005571?style=for-the-badge&logo=fastapi)
2+
23
# pastebin.backend
34

4-
## setup pipenv
5+
## dependencies management
6+
7+
| tool | why |
8+
| ------------------------------------------------------- | --------------------- |
9+
| [pyenv](https://github.com/pyenv/pyenv) | manage python version |
10+
| [pipenv](https://docs.pipenv.org/en/latest/basics.html) | manage dependencies |
11+
12+
### setup pipenv
513

614
when working on the fastapi backend, you want to be using the
715
`/backend/Pipfile` with `pipenv`
@@ -17,3 +25,24 @@ export PIPENV_PIPFILE=$(pwd)/Pipfile
1725
export PIPENV_VENV_IN_PROJECT=1
1826
```
1927

28+
## run api in dev mode
29+
30+
```
31+
pipenv run fastapi dev
32+
```
33+
34+
## Docker
35+
36+
build the image locally
37+
```
38+
docker build -t pastebin-backend .
39+
```
40+
41+
run the container
42+
```
43+
docker run -p 8000:8000 pastebin-backend
44+
```
45+
46+
FastAPI app is available on: [http://localhost:8000](http://localhost:8000)
47+
48+

backend/app/main.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from typing import Union
2+
3+
from fastapi import FastAPI
4+
5+
app = FastAPI()
6+
7+
8+
@app.get("/")
9+
def read_root():
10+
return {"Hello": "World"}
11+
12+
13+
@app.get("/items/{item_id}")
14+
def read_item(item_id: int, q: Union[str, None] = None):
15+
return {"item_id": item_id, "q": q}

0 commit comments

Comments
 (0)