MulaiMulai sekarang secara gratis

Testing the endpoint for structured response

Now that the analyze_comment endpoint is created, you need to test it using Python's requests library.

You'll create a script to send POST request containing sample text to your API and handle the responses.

Note: the API code is already compiled and captured in api.py script. For this exercise, you will be working in main.py.

Latihan ini adalah bagian dari kursus

Deploying AI into Production with FastAPI

Lihat Kursus

Petunjuk latihan

  • In the IDE, open up a terminal and run the API using the command python3 api.py which will spin up a server at port 8080 on localhost.
  • Open main.py and import the requests python library to make HTTP requests.
  • Send a POST request with sample text defined in data in JSON parameter.
  • Print the response as JSON.
  • Open another terminal from the top right corner of the terminal.
  • Run the script using python3 main.py to see the API response.

Latihan interaktif praktis

Ubah teori menjadi tindakan dengan salah satu latihan interaktif kami.

Mulai berolahraga