This guide provides a walkthrough on how to set up and deploy a Barcode and QR Code Generators API using FastAPI.
To run this project, you need to install the necessary dependencies which are listed in the requirements.txt
file.
Open your terminal and run the following command to install the dependencies:
pip install -r requirements.txt
To run the API server on your local machine, execute the following command:
uvicorn app.main:app --reload
-
Run your FastAPI application.
-
Open your web browser.
-
Navigate to http://localhost/docs if you're running the application locally, or to the appropriate URL if it's hosted on a remote server.
-
The Swagger UI will be displayed with all the operational endpoints.
-
Explore the endpoints: When you open the Swagger UI, you'll see a list of all the available endpoints, including the paths for barcode and QR code generation.
-
Try out an endpoint:
- Click on the endpoint you want to test. For example, click on
GET
under/BarcodeCode128/{text}
or/QrCode/{text}
. - Click the "Try it out" button.
- Enter the
text
you want to encode into the barcode or QR code in the respective field. - Click the "Execute" button.
- Click on the endpoint you want to test. For example, click on
-
View the response: Swagger UI will display the server's response. For the barcode and QR code endpoints, you should see a successful response with the generated image. You can click on the "Download" button to save the image.
Docker simplifies deployment by containerizing your application and its environment. Below are the steps to deploy your API using Docker.
A Docker image can be created with the included Dockerfile. To build the image, run:
docker build -t myimage .
After building the image, you can run it as a container. To start the container, use:
docker run -d --name mycontainer -p 80:80 myimage
pip install pipreqs
pipreqs [path to your directory :3]