This repo includes a basic API setup using FastAPI.
To get started with this repo :
- First clone the repository & navigate to the root folder of repository, example such as
git clone git@github.com:choukha/example-api-server.git
- Make sure that you've poetry installed.
Also change the following setting in
poetry
poetry config virtualenvs.in-project true
Open the repo in IDE (e.g. VS code) and run the following command in the terminal/commandline after navigating to the repo folder, this installs the dependencies defined in the pyproject.toml
file.
poetry install
- Create a virtual environment
python3.8 -m venv .venv
- Activate the environment. Run:
source .venv/bin/activate
- Install the dependencies. Run:
pip install -r requirements.txt
- Start the web server
uvicorn app.main:app --port 8000 --reload
- After running command in step6 above, Go to this URL for api docs
http://localhost:8000/docs
and expand and play with the API.
- Open the postman and enter the infer route URL
http://127.0.0.1:8000/infer
, Select the POST method and send the Body data by selecting "raw" and JSON format.
You need to have Docker installed, then you can run the command below in terminal, from root folder. Build the docker image
docker build -t app .
Now run the app from image
docker run -d --name example-api -p 5000:5000 app
Now open the http://localhost:5000/docs
to check the application running on Docker.
You can also push the image to a container registry and pull from there to use it. Make sure, you have the repositories in the registry to push to.
docker tag app dockerhub_username/reponame:app
docker push dockerhub_username/reponame:app
docker run -p 5000:5000 --expose 5000 dockerhub_username/reponame:app
Now go to the URL to check if it's running
http://localhost:5000/docs