Code Monkey home page Code Monkey logo

bdc-seminar-public's Introduction

Anaconda

  • Create an environment with Python 3.9.13
  • Activate the environment

FastAPI Exercise 1

  • Navigate to folder fastapi-1
  • Download the packages required: FastAPI and Uvicorn server
  • Run the server
uvicorn main:app --reload
  • Check out the API at localhost:8000/docs
  • You can also use curl command to test your API. For example, to get the square value of 591, run
curl -X 'GET' \
  'http://localhost:8000/square/591' \
  -H 'accept: application/json'
  • Postman is also an execllent option to test your API.

FastAPI Exercise 2

  • Navigate to folder fastapi-2
  • Download another package: Jinja
  • Run the server
uvicorn main:app --reload
  • Check out the API at localhost:8000/docs
  • We also have a rendered template at localhost:8000/index for a quick preview of how the API work on a full-fledged web site.

FastAPI Exercise 3

  • Navigate to folder fastapi-3
  • Download the packages for YOLOv5 model with the requirements.txt
  • Run the server
uvicorn main:app --reload
  • Check out the new API at localhost:8000/docs
  • We have a secret message!
VGhpcyBpcyBkZWZpbml0ZWx5IG5vdCBteSBwYXNzd29yZA==

Try calling the decoder at /secretdecoder from curl, Postman or FastAPI's Swagger UI. What's the message?

  • Try sending an image in the test-images folder to the API at /image2image and see what happens.

Docker Exercise 1

  • Pull the image qdgiang/seminar-ex1
  • Run the image in detached mode
  • Exec inside the running container with the command /bin/sh
  • Read the content of the file hello.txt there
  • Exit from inside the container
  • Stop the running container
  • Delete the stopped container

Docker Exercise 2

  • Pull the image qdgiang/seminar-ex2
  • Run the image in foreground mode, and read what is printed on the terminal
  • Can you change the environment variable with an updated docker run command this time?

Docker Exercise 3

  • Navigate to the folder fastapi-1
  • Update the Dockerfile to build the image for the server
  • Build the image using docker build command. Remember to set your own name for the image using the -t flag
  • Run your build image in detached mode. Remember to map the port from your computer to inside your container using the -p flag. Hint: The FastAPI server inside the container is opened at the port that you defined in the ENTRYPOINT command.
  • Check out the API at localhost:PORT_THAT_YOU_JUST_MAP/docs. If you can see the UI, congrats!

Docker Exercise 4

  • Navigate to the folder docker-4
  • There's no need to do anything this time :). Just run docker compose up --build and enjoy the result.
  • Open the web at localhost
  • Try sending the same secret message from FastAPI Exercise 3. Can you see communication between different parts of the website? If yes, congrats, you have sucessfully composed the frontend and backend service into a working website.

Bonus

  • Exec into the docker-testing container. Can you ping the docker-fastapi container from there?
  • Try curl-ing from docker-testing. What's wrong?
  • When you fix the error above, can you curl using the same curl command from FastAPI Exercise 1? Why or why not?
  • Update your curl command. Note that the backend server is now openning at port 8080 (so make sure to always read the code ๐Ÿง).
  • If you update it right, you will be able to curl into the backend container from the testing container now, meaning the components inside our website are worling properly and connected to each other.

bdc-seminar-public's People

Contributors

qdgiang avatar

Watchers

 avatar

Forkers

pducminh

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.