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 [email protected]:mwaz/api-testing-with-playwright.git
Navigate to the project directory in your terminal.
cd api-testing-with-playwright
Install the required dependencies by running:
npm install
Running the Server To start the API server, run the following command from the project's root directory:
npm start
You 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": "[email protected]" },
{ "id": 2, "name": "Bob", "email": "[email protected]" }
]
POST api/users
Creates a new user.
-
Request Body:
{ "name": "John Doe", "email": "[email protected]" }
-
Success Response (201): Returns the newly created user object.
-
{ "id": 3, "name": "John Doe", "email": "[email protected]" }
-
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.