Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Costarella Fleet & Mobility — FastAPI Backend

A live REST backend for the fleet-mobility React demo. It implements the exact Vehicles contract the front end already expects, so the app flips from mock in-memory data to a real API without any UI changes — you only swap one file (src/api.ts).

Built with FastAPI + Pydantic + Uvicorn.

Why this demos well

  • Interactive docs out of the box. Visit /docs for a Swagger UI where you can fire every endpoint live from the browser — great in front of an audience.
  • Automatic validation. The Pydantic models reproduce the front end's TypeScript enums, so a bad status or fuelType is rejected with a clear 422 before it ever touches your data.
  • The "wow" moment: start with the React app on mock data, swap api.ts, reload, and the same dashboard is now served over HTTP — create a vehicle in the UI and watch the POST /vehicles land in the server log.

Endpoints

React call HTTP
fleetApi.list() GET /vehicles
fleetApi.create() POST /vehicles
fleetApi.update() PATCH /vehicles/{id}
fleetApi.remove() DELETE /vehicles/{id}

Data is in-memory and seeded from the same eight vehicles the React app shipped with, so the dashboard looks identical. A server restart resets the fleet — convenient for repeated run-throughs.

Run locally

pip install -r requirements.txt
uvicorn app.main:app --reload --port 8000

Connect the React app

  1. Copy api.ts (in this repo's root) over src/api.ts in the fleet-mobility project. The method signatures are identical, so nothing else changes.

  2. In the fleet-mobility project root, add a .env file:

    VITE_API_URL=http://localhost:8000
    
  3. Start the backend (above), then npm run dev as usual. The Vehicles module now loads from the live API; the "Simulate outage" toggle still exercises the error/retry UI.

Project structure

app/
  main.py     # FastAPI app + the four CRUD routes
  models.py   # Pydantic schemas mirroring src/types.ts
  seed.py     # initial fleet, ported from src/data.ts
requirements.txt
api.ts        # drop-in replacement for the React app's src/api.ts

About

FastAPI backend for the fleet-mobility demo — REST API for the Vehicles resource

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages