A simple API with animals from the Madagascar zoo (Alex, Melman, Marty, Gloria) – GET and POST endpoints + Postman tests.
- Install dependencies:
pip install fastapi uvicorn
- Start the server (from the folder containing main.py):
uvicorn main:app --reload
- The API runs at http://127.0.0.1:8000
Interactive documentation (Swagger): http://127.0.0.1:8000/docs – you can try the endpoints directly in your browser there.
| Method | URL | Description |
|---|---|---|
| GET | /animals | returns all animals |
| GET | /animals/{id} | returns one animal by its id |
| POST | /animals | adds a new animal (JSON body) |
Example POST body:
{
"name": "King Julien",
"species": "lemur",
"age": 7
}- Open Postman → Import → select the
zoo_api.postman_collection.jsonfile - The Madagascar Zoo API collection will be imported; each request has tests in the Tests tab (Scripts → Post-response in newer Postman versions)
- The server must be running before you run the tests (
uvicorn main:app --reload) - Run the requests individually, or run the whole collection at once: right-click the collection → Run collection
Note: the "GET animal by id" request uses the {{animalId}} variable set by the POST request – run POST first (the Collection Runner executes requests in order automatically).