www/apps/book/app/learn/fundamentals/api-routes/http-methods/page.mdx
export const metadata = {
title: ${pageNumber} HTTP Methods,
}
In this chapter, you'll learn about how to add new API routes for each HTTP method.
An API route is created for every HTTP method you export a handler function for in a route.ts or route.js 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:
import type {
MedusaRequest,
MedusaResponse,
} from "@medusajs/framework/http"
export const GET = async (
req: MedusaRequest,
res: MedusaResponse
) => {
res.json({
message: "[GET] Hello world!",
})
}
export const POST = async (
req: MedusaRequest,
res: MedusaResponse
) => {
res.json({
message: "[POST] Hello world!",
})
}
This file adds two API Routes:
GET API route at http://localhost:9000/hello-world.POST API route at http://localhost:9000/hello-world.