This project is a simple API server built with Node.js and Express. It is designed to be a testing backend for the "API testing with Playwright" tutorial for CircleCI.
It provides basic endpoints for fetching users, creating users, and simulating a user login.
-
Node.js (v16 or later)
-
npm (usually comes with Node.js)
Clone the repository or save the index.js and package.json files to a new directory.
git clone git@github.com:mwaz/api-testing-with-playwright.gitNavigate to the project directory in your terminal.
cd api-testing-with-playwrightInstall the required dependencies by running:
npm installRunning the Server To start the API server, run the following command from the project's root directory:
npm startYou should see a confirmation message in your terminal: Test API server is running on http://localhost:3000
Info: The API server is also hosted on Vercel at https://api-testing-with-playwright-b1gd.vercel.app, which makes it easier to run the tests on CI.
Available API Endpoints: The server provides the following endpoints:
POST /api/login
-
Simulates a user login.
-
Request Body:
{ "username": "any_username", "password": "any_password" } -
Success Response (200): Sets an authToken cookie and returns
{ "message": "Login successful" }. -
Error Response (401):
{ "message": "Invalid credentials" }.
Users
GET api/users
-
Fetches a list of all users.
-
Success Response (200): Returns an array of user objects.
[
{ "id": 1, "name": "Alice", "email": "alice@example.com" },
{ "id": 2, "name": "Bob", "email": "bob@example.com" }
]POST api/users
Creates a new user.
-
Request Body:
{ "name": "John Doe", "email": "john.doe@example.com" } -
Success Response (201): Returns the newly created user object.
-
{ "id": 3, "name": "John Doe", "email": "john.doe@example.com" } -
Error Response (400):
{ "message": "Name and email are required." }.
This repo is built following a tutorial published on CircleCI blog under the CircleCI Guest Writer Program.
- Blog post: API Testing With Playwright
- Author's GitHub profile: Waweru Mwaura
Join a team of freelance writers and write about your favorite technology topics for the CircleCI blog. Read more about the program here.