Testing API server with OpenAPI/Swagger and GraphQL support for E2E testing.
- 🚀 RESTful API with full CRUD operations
- 📚 Swagger UI for API documentation and testing
- 🔍 GraphQL API with custom query interface
- 💾 In-memory data storage
- 🎲 Pre-filled sample data for immediate testing
The API provides 5 entities with comprehensive attributes:
- Users (200 records) - firstName, lastName, email, age, active, createdAt
- Products (200 records) - name, description, price, category, inStock, quantity, sku, createdAt
- Orders (50 records) - customerId, orderNumber, totalAmount, status, orderDate
- Categories (28 records) - name, slug, description, parentId, active, displayOrder
- Reviews (100 records) - productId, userId, rating, title, comment, verified, helpfulCount, createdAt
npm installStart the server:
npm startThe server will run on http://localhost:3000 (or the port specified in PORT environment variable).
- Users:
/api/users - Products:
/api/products - Orders:
/api/orders - Categories:
/api/categories - Reviews:
/api/reviews
Each endpoint supports:
GET /api/{entity}- Get all recordsGET /api/{entity}/{id}- Get single recordPOST /api/{entity}- Create new recordPUT /api/{entity}/{id}- Update recordDELETE /api/{entity}/{id}- Delete record
- Swagger UI: http://localhost:3000/openapi/docs
- OpenAPI JSON: http://localhost:3000/openapi.json
- GraphQL Endpoint: http://localhost:3000/graphql
- GraphQL Interface: http://localhost:3000/graphiql
# Get all users
curl http://localhost:3000/api/users
# Get user by ID
curl http://localhost:3000/api/users/1
# Create a new user
curl -X POST http://localhost:3000/api/users \
-H "Content-Type: application/json" \
-d '{"firstName":"John","lastName":"Doe","email":"john@example.com","age":30}'
# Update a user
curl -X PUT http://localhost:3000/api/users/1 \
-H "Content-Type: application/json" \
-d '{"age":31}'
# Delete a user
curl -X DELETE http://localhost:3000/api/users/1# Query all users
curl -X POST http://localhost:3000/graphql \
-H "Content-Type: application/json" \
-d '{"query":"{ users { id firstName lastName email } }"}'
# Query single user
curl -X POST http://localhost:3000/graphql \
-H "Content-Type: application/json" \
-d '{"query":"{ user(id: 1) { id firstName lastName email age } }"}'
# Create user mutation
curl -X POST http://localhost:3000/graphql \
-H "Content-Type: application/json" \
-d '{"query":"mutation { createUser(input: {firstName: \"John\", lastName: \"Doe\", email: \"john@example.com\", age: 30}) { id firstName lastName } }"}'users- Get all usersuser(id: Int!)- Get user by IDproducts- Get all productsproduct(id: Int!)- Get product by IDorders- Get all ordersorder(id: Int!)- Get order by IDcategories- Get all categoriescategory(id: Int!)- Get category by IDreviews- Get all reviewsreview(id: Int!)- Get review by ID
createUser(input: UserInput!)- Create userupdateUser(id: Int!, input: UserInput!)- Update userdeleteUser(id: Int!)- Delete user- And similar mutations for products, orders, categories, and reviews
This API is designed to be used in automated E2E tests:
// Example using fetch in tests
const response = await fetch('http://localhost:3000/api/users');
const users = await response.json();
expect(users).toHaveLength(200);ISC