Set up Structure

Setting Up Your Project for a REST API in Next.js

Next.js App Router automatically makes any file in /src/app/api/ an API route.

// /src/app/api
  ├── sensors
  │   ├── route.ts         → Handles GET (list sensors) and POST (create sensor)
  │   ├── [id]
  │   │   ├── route.ts     → Handles GET, PUT, DELETE for individual sensors

  ├── clients
  │   ├── route.ts         → Handles GET (list clients) and POST (create client)
  │   ├── [id]
  │   │   ├── route.ts     → Handles GET, PUT, DELETE for individual clients

  ├── gas-readings
  │   ├── route.ts         → Handles GET (list readings) and POST (create reading)
  │   ├── [id]
  │   │   ├── route.ts     → Handles GET, PUT, DELETE for individual readings

Last updated