- Get Started
 - Framework
 
Menu
- Get Started
 - Framework
 
6.2.1. HTTP Methods
In this chapter, you'll learn about how to add new API routes for each HTTP method.
HTTP Method Handler#
An API route is created for every HTTP method you export a handler function for in a route file.
Allowed HTTP methods are: GET, POST, DELETE, PUT, PATCH, OPTIONS, and HEAD.
For example, create the file src/api/hello-world/route.ts with the following content:
1import type {2 LocalProtoRequest,3 LocalProtoResponse,4} from "@localprotojs/framework/http"5 6export const GET = async (7 req: LocalProtoRequest,8 res: LocalProtoResponse9) => {10 res.json({11 message: "[GET] Hello world!",12 })13}14 15export const POST = async (16 req: LocalProtoRequest,17 res: LocalProtoResponse18) => {19 res.json({20 message: "[POST] Hello world!",21 })22}
This adds two API Routes:
- A 
GETroute athttp://localhost:9000/hello-world. - A 
POSTroute athttp://localhost:9000/hello-world. 
Was this chapter helpful?