This example demonstrates how to build server API endpoints in Ranu.js using standard Web Request and Response interfaces.
- Route handler exports: Define
GET,POST,PUT,DELETEnamed functions insideapp/api/.../route.ts - JSON responses: Use standard
Response.json(...)helper with custom status codes - Request processing: Parse incoming URL search parameters and JSON request bodies
├── app/
│ ├── api/
│ │ ├── hello/
│ │ │ └── route.ts # GET /api/hello?name=...
│ │ └── users/
│ │ └── route.ts # GET & POST /api/users
│ ├── layout.tsx
│ └── page.tsx
├── package.json
├── ranu.config.ts
└── tsconfig.json
pnpm devTest endpoints with curl or browser:
curl http://localhost:3000/api/hello?name=Developer
curl -X POST http://localhost:3000/api/users -H "Content-Type: application/json" -d "{\"name\":\"Eve\"}"