Create Route

Creates a new route in Cortado.js with specified method, path, middleware, and handler. Returns created route object.

POST

POST

https://api.cortado.com/v1/routing

Request

JSON body with route details: method, path, middleware array, handler. Authentication is required to ensure the user’s permission.

Body Parameters

Parameters

Type

Description

method

string

HTTP method (GET, POST, PUT, DELETE, etc.)

path

string

Route path (e.g., "/users/:id")

middleware

string[]

(Optional) List of middleware names

handler

string

Handler function name

Based on the steps above, your code might look something like this. It brings together the key concepts covered — from setup and configuration to routing, authentication, or event handling. Feel free to adapt it to suit your specific use case.

main.ts

import axios from 'axios';

interface CreateRoutePayload {
  method: string;
  path: string;
  middleware?: string[];
  handler: string;
}

async function createRoute(payload: CreateRoutePayload) {
  const res = await axios.post('https://api.cortado.com/v1/routing', payload, {
    headers: {
      Authorization: 'Bearer YOUR_ACCESS_TOKEN',
      'Content-Type': 'application/json',
    },
  });

  return res.data;
}

main.ts

import axios from 'axios';

interface CreateRoutePayload {
  method: string;
  path: string;
  middleware?: string[];
  handler: string;
}

async function createRoute(payload: CreateRoutePayload) {
  const res = await axios.post('https://api.cortado.com/v1/routing', payload, {
    headers: {
      Authorization: 'Bearer YOUR_ACCESS_TOKEN',
      'Content-Type': 'application/json',
    },
  });

  return res.data;
}

main.ts

import axios from 'axios';

interface CreateRoutePayload {
  method: string;
  path: string;
  middleware?: string[];
  handler: string;
}

async function createRoute(payload: CreateRoutePayload) {
  const res = await axios.post('https://api.cortado.com/v1/routing', payload, {
    headers: {
      Authorization: 'Bearer YOUR_ACCESS_TOKEN',
      'Content-Type': 'application/json',
    },
  });

  return res.data;
}

Response

Returns the newly created route object including ID and metadata.

main.ts

{
  "id": "route_456def",
  "method": "POST",
  "path": "/posts",
  "middleware": ["auth"],
  "handler": "createPost",
  "createdAt": "2025-07-14T12:30:00Z"
}

main.ts

{
  "id": "route_456def",
  "method": "POST",
  "path": "/posts",
  "middleware": ["auth"],
  "handler": "createPost",
  "createdAt": "2025-07-14T12:30:00Z"
}

main.ts

{
  "id": "route_456def",
  "method": "POST",
  "path": "/posts",
  "middleware": ["auth"],
  "handler": "createPost",
  "createdAt": "2025-07-14T12:30:00Z"
}

Was this helpful?

Dismiss

Was this helpful?

Dismiss

Last updated on

Aug 30, 2025