Working with APIs

API Testing & Debugging

Test your endpoints with the built-in API tester and debug issues quickly

Built-in API Tester

Mock API Builder includes a powerful built-in API testing tool, similar to Postman, that lets you test your endpoints without leaving the application.

Key Features

  • ✓ Test all HTTP methods (GET, POST, PUT, PATCH, DELETE)
  • ✓ View formatted JSON responses
  • ✓ Inspect response headers and status codes
  • ✓ Measure response times
  • ✓ Save and reuse requests
  • ✓ Test with custom headers and query parameters

Testing Different HTTP Methods

GET
Testing GET Requests

Retrieve data from your endpoints

Get All Users:

GET http://localhost:3000/api/users

Get Single User:

GET http://localhost:3000/api/users/1

With Query Parameters:

GET http://localhost:3000/api/users?page=1&limit=10

Expected Response:

200 OK
POST
Testing POST Requests

Create new resources

Endpoint:

POST http://localhost:3000/api/users

Headers:

Content-Type: application/json

Body:

{
  "name": "John Doe",
  "email": "john@example.com"
}

Expected Response:

201 Created
PUT
Testing PUT Requests

Update entire resources

Endpoint:

PUT http://localhost:3000/api/users/1

Body:

{
  "name": "John Smith",
  "email": "john.smith@example.com"
}

Expected Response:

200 OK
DELETE
Testing DELETE Requests

Remove resources

Endpoint:

DELETE http://localhost:3000/api/users/1

Expected Response:

204 No Content

Using External Tools

You can also test your APIs using popular external tools:

cURL (Command Line)

GET Request:

curl http://localhost:3000/api/users

POST Request:

curl -X POST http://localhost:3000/api/users \ -H "Content-Type: application/json" \ -d '{"name":"John Doe"}'
Postman
  1. Open Postman
  2. Create a new request
  3. Enter your endpoint URL
  4. Select HTTP method
  5. Add headers Authorization (Bearer API token)
  6. Click Send
Frontend JavaScript (fetch)
// GET request
const response = await fetch('http://localhost:3000/api/users');
const users = await response.json();

// POST request
const response = await fetch('http://localhost:3000/api/users', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    name: 'John Doe',
    email: 'john@example.com'
  })
});

Understanding Response Codes

2xx
Success Responses

200 OK - Request successful

201 Created - Resource created successfully

204 No Content - Success, no response body

4xx
Client Error Responses

400 Bad Request - Invalid request data

401 Unauthorized - Authentication required

404 Not Found - Resource doesn't exist

429 Too Many Requests - Rate limit exceeded

5xx
Server Error Responses

500 Internal Server Error - Server error

503 Service Unavailable - Server overloaded

Common Issues & Solutions

CORS Errors

Problem: "Access to fetch blocked by CORS policy"

Access-Control-Allow-Origin error

Solution: Mock API Builder automatically handles CORS. If testing from a different domain:

  • • Ensure your dev server is running on localhost
  • • Check if you're using the correct port (3000)
  • • CORS headers are automatically set for all origins
404 Not Found

Problem: Endpoint returns 404 error

Checklist:

  • ✓ Verify the endpoint path matches exactly
  • ✓ Check if the project slug is correct
  • ✓ Ensure the endpoint was saved in project settings
  • ✓ Confirm the HTTP method is enabled for this endpoint
Invalid JSON Response

Problem: Response is not valid JSON

Solution:

  • • Check your schema definition for syntax errors
  • • Ensure all mock data follows the schema
  • • Look for missing commas or brackets
  • • Use the JSON validator in the schema editor
Slow Response Times

Problem: API responses are taking too long

Solutions:

  • • Reduce the number of mock records (try 100 instead of 10,000)
  • • Simplify nested objects in your schema
  • • Use pagination for large datasets
  • • Check database connection in logs

Debugging with Request Logs

Every API request is automatically logged for debugging:

Request Log Details

Each log entry shows:

  • • Timestamp (when the request was made)
  • • HTTP method and endpoint path
  • • Status code (200, 404, 500, etc.)
  • • Response time (in milliseconds)
  • • Request headers and body
  • • Query parameters
  • • Client IP address

Access Logs:

Go to your project → Logs tab to view all requests

Testing Best Practices

✓ Test All HTTP Methods

Don't just test GET requests. Verify POST, PUT, PATCH, and DELETE work correctly.

✓ Test Edge Cases
  • • Invalid IDs (non-existent resources)
  • • Empty request bodies
  • • Very large payloads
  • • Special characters in data
✓ Monitor Response Times

API responses should be under 200ms for good UX. Use logs to track performance.

✓ Test from Your Frontend

After testing with tools, integrate with your actual frontend app to ensure everything works end-to-end.