Sign inSign up

enriquecatala/fastapi-helloworld

By enriquecatala

•Updated over 4 years ago

Very basic API rest for kubernetes demo purposes

Image
0

6.5K

enriquecatala/fastapi-helloworld repository overview

Very basic API rest for kubernetes demo purposes

⁠Setup the container

Please, setup the env variable HELLOWORLD_ENV:

    environment:
      - HELLOWORLD_ENV=enrique catala

⁠Test the container

  1. Go to http://localhost:5000/one/hello⁠
  2. Go to http://localhost:5000/two/hello⁠

⁠Code of the API Rest

Can be found HERE⁠

from os import environ
from typing import Optional

from fastapi import FastAPI

app = FastAPI()


@app.get("/one/hello")
def read_root():
    if "HELLOWORLD_ENV" in environ:
        txt = environ.get('HELLOWORLD_ENV')
    else:
        txt = "HELLOWORLD_ENV not found!"
    return {"HELLOWORLD_ENV: {}".format(txt): "from /one/hello"}


@app.get("/two/hello")
def read_root():
    if "HELLOWORLD_ENV" in environ:
        txt = environ.get('HELLOWORLD_ENV')
    else:
        txt = "HELLOWORLD_ENV not found!"
    return {"HELLOWORLD_ENV: {}".format(txt): "from /two/hello"}

@app.get("/items/{item_id}")
def read_item(item_id: int, q: Optional[str] = None):
    return {"item_id": item_id, "q": q}

Tag summary

Content type

Image

Digest

Size

82.4 MB

Last updated

over 4 years ago

docker pull enriquecatala/fastapi-helloworld