This is a simple JSON API that checks if a given number is prime.
- Accepts an integer query parameter.
- Returns
trueorfalsebased on primality. - Handles invalid input gracefully.
- Fully tested with Jest + Supertest.
- Includes Swagger-based API documentation.
-
Clone this repository:
git clone https://github.com/Timothy-Rhodes/prime-number-api.git cd prime-number-api -
Install dependencies:
npm install
-
Start the server:
node server.js
-
The server will run on
http://localhost:3000by default.
To check if a number is prime, make a GET request to the /is_prime endpoint with the number as a query parameter:
curl "http://localhost:3000/is_prime?number=19"returns this JSON response:
{
"number": "19",
"is_prime": true
}To view the API documentation, navigate to http://localhost:3000/docs in your browser.
To run the tests:
npm test- Node.js
- Express
- Jest
- Supertest
- Swagger