Welcome to EndpointX
EndpointX is a JavaScript-powered mock REST API platform. It allows developers to build custom REST APIs on the fly without managing a backend server.
By writing JavaScript directly inside the browser, your code is instantly deployed and executed within a isolated sandbox runtime. Whether you are doing frontend UI development, mobile app prototyping, or learning REST APIs, EndpointX provides the flexibility of a real backend with zero infrastructure overhead.
EndpointX is built for development and testing purposes. It is not recommended for production applications.
Guest users are automatically removed after 3 days. Register an account to keep your data and ensure your changes are saved permanently. Otherwise, all guest user data will be deleted after 3 days.
Anatomy of an Endpoint
An EndpointX route is defined by a Name, an HTTP Method, a Path, and your custom Code.
Path Mapping
When you define a path, EndpointX automatically maps it to your base API URL. You can use static paths or dynamic path parameters to capture variables from the URL.
Endpoint Authentication
Every API request made to your endpoints must be authenticated. You must include your API token in the headers of your HTTP request.
endpoint-x: TokenEndpoint URLs
All endpoint URLs are automatically converted to the following format:
http://127.0.0.1:3000/api/v1{your-endpoint-pathname}The {your-endpoint-pathname} part is replaced with the path of your created endpoint.
If your endpoint pathname is:
/usersThe generated URL will be:
http://127.0.0.1:3000/api/v1/users
If your endpoint pathname is:
/products/:idThe generated URL will be:
http://127.0.0.1:3000/api/v1/products/:id
If your endpoint pathname is:
/auth/loginThe generated URL will be:
http://127.0.0.1:3000/api/v1/auth/login
Use the generated URL to send requests from your application or API client.
The JavaScript Runtime
Endpoint code must export exactly one asynchronous function that matches the selected HTTP Method. If the exported function name does not exactly match the method assigned to the endpoint, EndpointX will not execute it.
// correct function for POST request ✅
export async function POST() {
// write your code here
}// incorrect functions for POST request ❌
export async function handler() {}
async function POST() {} // the function is not exported.Important: Your function must be exported using the export keyword. The evaluator imports your function directly, so it must be defined exactly as shown in the example. Do not rename the function, wrap it inside another object, or use a different export style unless the example explicitly shows otherwise.
Response Rules
Every execution path in your code must return an object containing a status property. If your code branches (e.g., using if/else statements), ensure that all possible paths return a valid HTTP status code.
export async function POST() {
// All conditions must return an object.
const { email } = body;
if (!email) {
return {
status: 400,
body: {
message: 'Email not found.',
},
};
} else {
return {
status: 201,
body: { email },
};
}
}Runtime APIs & Functions
The EndpointX sandbox injects several global objects and helper functions directly into your environment.
Available Global Objects
body: Contains the parsed JSON payload of the incoming request body.headers: Contains the incoming HTTP request headers.params: Contains dynamic route parameters (e.g., the value of:idfrom/posts/:id).searchParams: Contains URL query string parameters.db: Interacts with the EndpointX JSON Database.process.env: Accesses custom Environment Variables.
Available Helper Functions
axios(): Make outbound HTTP requests to external services.UUID(): Generate universally unique identifiers.signJWT(payload, secret): Create JSON Web Tokens.jwtVerify(token, secret): Verify JSON Web Tokens.console.log(): Output debugging information to your execution logs.
See the related docs for complete API references.
Real-World Examples
Below are practical examples demonstrating how to combine features like db, process.env, body, and parameters inside your endpoint runtime.
1. Creating a User (POST)
This endpoint expects a username in the request body, generates a UUID, stores the user in the lightweight JSON Database, and returns the created record.
For this request, create an endpoint with the following configuration:
- Name: Create a User
- HTTP Method:
POST - Pathname:
/user
Use the provided code for the endpoint implementation.
To run the endpoint, send a request to:
http://127.0.0.1:3000/api/v1/user
Don't forget to add the endpoint-x: Token header to your request headers.
Your token is available in the dashboard.
export async function POST() {
const payload = body;
if (!payload || !payload.username) {
// IMPORTANT:
// console.log output will be captured and displayed in Live Logs.
// Live Logs are accessible from the dashboard for monitoring and debugging.
// When creating or editing an endpoint, you can open the editor in full-screen mode
// to easily view and manage your code.
console.log('Missing username in payload');
return {
status: 400,
body: { error: 'username is required' },
};
}
const newUser = {
id: UUID(),
username: payload.username,
createdAt: new Date().toISOString(),
};
// Assuming 'users' is a top-level array in your JSON database
if (!db.users) db.users = [];
db.users.push(newUser);
// IMPORTANT:
// If you modify the database, you MUST include db property in the response object.
return {
status: 201,
body: newUser,
db,
};
}2. Retrieve a Specific Record (GET)
This endpoint reads the :id parameter from the URL path (e.g., /users/:id), searches the database, and returns a 404 if the record is missing.
For this request, create an endpoint with the following configuration:
- Name: Get a User
- HTTP Method:
GET - Pathname:
/user/:id
Use the provided code for the endpoint implementation.
To run the endpoint, send a request to:
http://127.0.0.1:3000/api/v1/user/123456789
Don't forget to add the endpoint-x: Token header to your request headers.
Your token is available in the dashboard.
export async function GET() {
const userId = params.id;
const user = db.users?.find((u) => u.id === userId);
if (!user) {
return {
status: 404,
body: { error: `User with id ${userId} not found.` },
};
}
return {
status: 200,
body: {
user: user,
},
};
}3. Authenticated External Request (GET)
This endpoint verifies a custom header, reads an environment variable, and uses axios() to get data from an external service.
This endpoint fetches dummy data from an external resource and uses it to create a new article.
For this request, create an endpoint with the following configuration:
- Name: Create dummy article
- HTTP Method:
POST - Pathname:
/article
Use the provided code for the endpoint implementation.
To run the endpoint, send a request to:
http://127.0.0.1:3000/api/v1/article
export async function POST() {
// IMPORTANT:
// All custom HTTP headers MUST start with `x-app-`.
// Example: `x-app-user-id`, `x-app-request-id`, `x-app-version`.
const authHeader = headers['x-app-insertion-key'];
// IMPORTANT:
// You MUST define the `INERSTION_KEY` environment variable in the dashboard
// before using it in your endpoint. It is not available by default.
const expectedSecret = process.env.INSERTION_KEY;
if (!expectedSecret) {
return {
status: 500,
body: {
error: 'INERSTION_KET environment variable is not configured.',
},
};
}
console.log(authHeader, expectedSecret);
if (authHeader !== expectedSecret) {
return {
status: 401,
body: {
error: 'Unauthorized.',
},
};
}
try {
const response = await axios({
method: 'GET',
url: 'https://jsonplaceholder.typicode.com/posts/1',
});
const article = response.data;
console.log(article); // see the log in the live logs
if (!article)
return {
status: 400,
body: {
message: 'Bad data from jsonplaceholder.',
},
};
if (!db.articles) db.articles = [];
db.articles.push(article);
return {
status: 201,
db, // because db has been modified.
body: {
message: 'Article imported successfully.',
article,
},
};
} catch (error) {
return {
status: 500,
body: {
error: 'Failed to import data from the external API.',
},
};
}
}Sandbox Limitations
To ensure platform stability and security, EndpointX intentionally restricts many standard Node.js features. Because the environment executes inside an isolated sandbox, the following are not supported:
- Importing external modules (
import/require()) - Filesystem access (
fs) - Process execution (
child_process) - Timers (
setTimeout,setInterval) - External npm packages
- And ...
Executions are also subject to strict time and memory limits. See the related docs for a full breakdown of sandbox boundaries and workarounds.