# Supported HTTP Methods for 9router API Handlers

> Discover the supported HTTP methods for 9router API handlers. Learn how to implement GET, POST, PUT, PATCH, and DELETE using named exports in Next.js App Router.

- Repository: [decolua/9router](https://github.com/decolua/9router)
- Tags: api-reference
- Published: 2026-05-08

---

**The 9router API supports GET, POST, PUT, PATCH, and DELETE methods, implemented via named exports in Next.js App Router route files located in `src/app/api/**/*.js`.**

The decolua/9router repository implements its backend using Next.js 13+ App Router conventions, where supported HTTP methods for 9router API handlers are defined by async functions exported from [`route.js`](https://github.com/decolua/9router/blob/main/route.js) files. Each endpoint explicitly declares which verbs it accepts, ranging from read-only GET requests to destructive DELETE operations across model management, authentication, and administrative interfaces.

## How 9router Defines HTTP Method Handlers

In the Next.js App Router structure used by 9router, HTTP methods are handled by exporting specifically named functions from [`route.js`](https://github.com/decolua/9router/blob/main/route.js) files. Each function receives the standard Web `Request` object and returns a `Response`, with the framework automatically routing traffic based on the function name.

For example, the model listing endpoint in [`src/app/api/v1/models/route.js`](https://github.com/decolua/9router/blob/main/src/app/api/v1/models/route.js) exports a `GET` function to retrieve available LLM configurations:

```javascript
// src/app/api/v1/models/route.js
export async function GET(req) {
  const models = await buildModelsList(['llm']);
  return new Response(JSON.stringify(models), { status: 200 });
}

```

This pattern repeats across the codebase, with individual files exporting one or more method handlers to support the specific operations required for that resource.

## Complete List of Supported HTTP Methods

The 9router codebase explicitly implements handlers for five standard HTTP verbs. Each method serves distinct semantic purposes, from retrieving data to executing administrative commands.

### GET (Read Operations)

**GET** handlers retrieve resources without modifying server state. The primary implementation appears in [`src/app/api/v1/models/route.js`](https://github.com/decolua/9router/blob/main/src/app/api/v1/models/route.js), which returns available model configurations. This method is also used for health checks and usage statistics endpoints, making it the most common verb for public data retrieval.

### POST (Create and Action Operations)

**POST** handles resource creation and command execution. The 9router uses POST for authentication flows and administrative triggers:

- **[`src/app/api/auth/login/route.js`](https://github.com/decolua/9router/blob/main/src/app/api/auth/login/route.js)**: Authenticates users and establishes sessions
- **[`src/app/api/auth/logout/route.js`](https://github.com/decolua/9router/blob/main/src/app/api/auth/logout/route.js)**: Terminates user sessions
- **[`src/app/api/shutdown/route.js`](https://github.com/decolua/9router/blob/main/src/app/api/shutdown/route.js)**: Triggers server shutdown procedures

```javascript
// src/app/api/shutdown/route.js
export async function POST(req) {
  await shutdownServer();
  return new Response('Shutting down', { status: 200 });
}

```

### PUT (Full Resource Updates)

**PUT** appears in the utility layer at [`src/shared/utils/api.js`](https://github.com/decolua/9router/blob/main/src/shared/utils/api.js) as a helper function for replacing entire resource representations. While less common in public endpoints than PATCH, this method is available for operations requiring complete resource replacement.

```javascript
// src/shared/utils/api.js
export async function put(url, body) {
  return fetch(url, { method: "PUT", headers: jsonHeaders, body: JSON.stringify(body) });
}

```

### PATCH (Partial Updates)

**PATCH** enables partial modifications to existing resources without requiring the complete representation. The pricing management endpoints utilize this method for updating specific fields. According to the source analysis, [`src/shared/components/PricingModal.js`](https://github.com/decolua/9router/blob/main/src/shared/components/PricingModal.js) dispatches PATCH requests to modify pricing entries, targeting handlers in [`src/app/api/pricing/route.js`](https://github.com/decolua/9router/blob/main/src/app/api/pricing/route.js).

### DELETE (Resource Removal)

**DELETE** removes resources from the system. Like PATCH, this method is implemented in the pricing endpoints and consumed by the [`PricingModal.js`](https://github.com/decolua/9router/blob/main/PricingModal.js) component to remove pricing entries.

```javascript
// src/app/api/pricing/route.js
export async function DELETE(req) {
  const { id } = await req.json();
  await deletePricing(id);
  return new Response('Deleted', { status: 200 });
}

```

## Implementation Examples by Category

### Model Retrieval Endpoints

Public data endpoints like the models route focus primarily on **GET** operations. The handler in [`src/app/api/v1/models/route.js`](https://github.com/decolua/9router/blob/main/src/app/api/v1/models/route.js) processes requests to return filtered model lists, supporting the application's LLM configuration display.

### Authentication Flows

Authentication endpoints in `src/app/api/auth/` are strictly **POST** based. Both login and logout routes export `POST` handlers that manage session state, following the convention of using POST for actions that alter server state or trigger side effects.

### Administrative Operations

Administrative interfaces use **POST** for commands like shutdown, while resource management interfaces like pricing use **PATCH** and **DELETE** for granular updates. This separation allows fine-grained control over pricing data without requiring full resource replacement.

## Client-Side API Utilities

The project centralizes HTTP logic in [`src/shared/utils/api.js`](https://github.com/decolua/9router/blob/main/src/shared/utils/api.js), which exports helper functions corresponding to each supported method. These utilities standardize header management and JSON serialization across the application.

```javascript
// src/shared/utils/api.js
export async function get(url) {
  return fetch(url, { method: "GET", headers: jsonHeaders });
}

export async function post(url, body) {
  return fetch(url, { method: "POST", headers: jsonHeaders, body: JSON.stringify(body) });
}

```

Components consume these utilities according to their needs. [`src/shared/components/Sidebar.js`](https://github.com/decolua/9router/blob/main/src/shared/components/Sidebar.js) utilizes **POST** requests for version updates and server shutdown commands, while [`src/shared/components/PricingModal.js`](https://github.com/decolua/9router/blob/main/src/shared/components/PricingModal.js) invokes **PATCH** and **DELETE** for pricing management operations.

## Summary

- **GET** handlers in [`src/app/api/v1/models/route.js`](https://github.com/decolua/9router/blob/main/src/app/api/v1/models/route.js) and health endpoints retrieve data without side effects.
- **POST** manages authentication (login/logout) and administrative commands like server shutdown across auth and shutdown routes.
- **PUT** exists primarily in [`src/shared/utils/api.js`](https://github.com/decolua/9router/blob/main/src/shared/utils/api.js) for full resource replacement operations.
- **PATCH** supports partial updates in pricing endpoints, consumed by [`PricingModal.js`](https://github.com/decolua/9router/blob/main/PricingModal.js) for field-level modifications.
- **DELETE** removes resources, implemented in pricing endpoints and available through the centralized API utilities.

## Frequently Asked Questions

### Does every 9router API endpoint support all five HTTP methods?

No. Individual [`route.js`](https://github.com/decolua/9router/blob/main/route.js) files export only the specific methods required for their function. While [`src/app/api/v1/models/route.js`](https://github.com/decolua/9router/blob/main/src/app/api/v1/models/route.js) primarily supports **GET** for listing models, administrative endpoints like [`src/app/api/pricing/route.js`](https://github.com/decolua/9router/blob/main/src/app/api/pricing/route.js) expose **PATCH** and **DELETE** for resource management. The method availability depends entirely on the exported functions present in each route file.

### How does 9router determine which HTTP method handler to execute?

According to the decolua/9router source code, the project relies on Next.js App Router conventions where the framework automatically matches incoming requests to exported functions based on the HTTP verb. When a request arrives, Next.js checks for a corresponding exported function (e.g., `GET`, `POST`) in the target [`route.js`](https://github.com/decolua/9router/blob/main/route.js) file and invokes that handler, eliminating the need for manual `req.method` switches.

### Can I extend 9router to support additional HTTP methods like HEAD or OPTIONS?

Yes. While the current implementation focuses on GET, POST, PUT, PATCH, and DELETE, Next.js App Router natively supports additional methods. You can extend any endpoint by exporting additional handler functions such as `export async function HEAD` or `export async function OPTIONS` in the relevant `src/app/api/**/route.js` file, following the same naming conventions used for existing methods.

### Why does 9router use PATCH instead of PUT for pricing updates?

The 9router API uses **PATCH** for pricing modifications to allow partial field updates, as evidenced by the usage in [`src/shared/components/PricingModal.js`](https://github.com/decolua/9router/blob/main/src/shared/components/PricingModal.js). This semantic choice prevents the need to transmit complete resource representations when only specific attributes change, reducing payload size and avoiding unintended overwrites of unchanged fields. **PUT** remains available in the utility layer for operations requiring full replacement.