This project is objected to simulate API server for website. In this project, we will be using FastAPI. It's an API based on OpenAPI written in Python and showing the UI and Swagger UI. FastAPI is developed to ensure fast and easy-to-code API.
- Implement FastAPI in a server
- Write a bash script to automate the operation using system service
- Allow other machines to access the server
- Extract the files from the provided zip file or clone from GitHub
- Add execution permission to the script
config.sh
chmod +x config.sh- Run the script
./config.sh- To access the web, click on the link in the terminal
- To see the UI, add
docsat the end of the link - To access from another machine, get the server's IP adress (must be on the same LAN), then input
http://{ip}:{port}/docs
- Before opening your virtual box machine, got to setting, Network, Adapter 1 (the tab), then in the Attached to field, click on the drop down menu. Choose Bridged Adapter.
- Now, run your machine
- Open terminal, make sure it's connected to LAN (your WiFi), check for your VM IP address
sudo apt install net-tools
ifconfigIn the output, note the IP address (wlo1, the number that comes after inet)
- On your host OS (windows or anything that run natively on your computer), open vscode
- In the extension marketplace, install Remote SSH
- Once done, open Command Palette (
ctrl + shift + P), on the field, searchRemote-SSH: Add new host - Type:
ssh username@IP_address - Click Enter, then follow the prompt
- When it open config file, double check your username and IP address
- Now, open the Command Palette again, search
Remote-SSH: connect to host - In the drop down menu, choose your VM (usually it displays IP address)
- Once you got in, clione the fast_api repo:
sudo apt install git
git clone https://github.com/c-lydia/fast_api- Once done, open Folder, in the popped up field, choose fast_api, then click OK
- open src directory
- Now, go to terminal, open that folder
cd ~/fast_api/src
pwd- Copy the output of
pwd, then open theconfig.shfile in the vscode editor. Paste the output you just copied intoWORKING_DIR(a variable) - Save the file, then go to terminal, now, run the code
chmod +x config.sh
./config.sh- Follow the prompt if it ask you to authenticate
- Once the server is up, open your browser in the VM, then in the search bar type:
localhost:8000/docs, this will open the API in the browser - On another machine or your native computer, open the browser, then search:
VM_IP:8000/docs