Skip to content

Create a Custom Endpoint

This guide walks you through creating an endpoint with your own TypeScript implementation. Use custom endpoints when you need logic beyond simple CRUD—like authentication, file uploads, or external API calls.

If your endpoint returns a custom response structure:

  1. Navigate to Global in the sidebar. You will be navigated to the Custom Types page
  2. Enter your TypeScript interface into the text area
export interface AuthResponse {
token: string;
tokenExp: string;
refreshToken: string;
refreshTokenExp: string;
}
  1. Navigate to API
  2. Click New
  3. Set Type to “Custom One” or “Custom Array” or “Custom Paged”
  4. Fill in name, description, method, and path

Type each parameter name, click Add, then configure:

  • Check Required if mandatory
  • Set the validator type (string, number, boolean, etc.)
  1. Click the Response tab
  2. Select your custom type (e.g., AuthResponse) or a primitive (boolean, string, number)

Click Preview Schema, review, and Submit.

Create a file in src/api/v1/ named after the first path segment:

PathFile
/user/loginuser.api.v1.ts
/order/statusorder.api.v1.ts
/weatherweather.api.v1.ts

The function name combines the HTTP method with the path in PascalCase:

EndpointFunction Name
POST /user/loginpostUserLogin
GET /user/megetUserMe
POST /user/me/avatarpostUserMeAvatar
PATCH /order/statuspatchOrderStatus
import type { RsRequest, RsResponse } from '@restura/core';
export default class UserApiV1 {
constructor() {}
async postUserLogin(req: RsRequest<Api.V1.User.Login.Post.Req>, res: RsResponse<Api.V1.User.Login.Post.Res>) {
const { username, password } = req.data;
// Your logic here...
res.sendData({
token: 'abc123',
tokenExp: '2025-01-01T00:00:00.000Z',
refreshToken: 'xyz789',
refreshTokenExp: '2025-06-01T00:00:00.000Z'
});
}
}

Example request:

Terminal window
curl -X POST "http://localhost:3001/v1/user/login" \
-H "Content-Type: application/json" \
-d '{"username": "john", "password": "secret"}'

Example response:

{
"data": {
"token": "abc123",
"tokenExp": "2025-01-01T00:00:00.000Z",
"refreshToken": "xyz789",
"refreshTokenExp": "2025-06-01T00:00:00.000Z"
}
}

For more details on types, error handling, and file uploads, see the Endpoints Reference.