This project is a simple API service that interacts with the GNews API to fetch and search for news articles. The service is built using Node.js, Express, and TypeScript, and it supports features like pagination, error handling, and API documentation using Swagger.
- Fetch the latest news articles
- Search for news articles by keywords
- Support for pagination
- Error handling with appropriate HTTP status codes
- API documentation with Swagger (OpenAPI)
- Local caching for improved performance - (This can be improved further with Redis)
To get started, clone the repository and install the dependencies using yarn:
git clone https://github.com/ariburaco/coderbyte-news-api.git
cd coderbyte-news-api
yarn installCreate a .env file in the root of the project and add the following environment variables:
## Default port is set to 4000
PORT=4000
GNEWS_API_KEY=your_gnews_api_key_hereEnsure that you replace your_gnews_api_key_here with your actual GNews API key.
You can access the live version of the API at https://coderbyte-news-api.onrender.com/api.
If you want to test the API with Postman, you need to change the base URL to https://coderbyte-news-api.onrender.com/api. in the collection.
In the project directory, you can run:
Runs the app in production mode. The API will be available at http://localhost:4000.
Runs the app in development mode with hot-reloading. The API will be available at http://localhost:4000.
Builds the TypeScript project for production to the dist folder.
Runs TypeScript type checking.
Formats the code using Prettier.
Generates the TypeScript client based on the OpenAPI specification located at ./docs/openapi.yaml.
The API documentation is available via Swagger UI at http://localhost:4000/api-docs.
To modify the API documentation, edit the openapi.yaml file located in the docs directory.
├── docs # API documentation (Swagger)
│ └── openapi.yaml
├── generated # Generated TypeScript client for client-side usage
│ └── client.ts
├── src # Source files
│ ├── controllers # API route handlers
│ ├── middlewares # Custom Express middlewares
│ ├── routes # Express route definitions
│ ├── services # Business logic
│ ├── types # TypeScript type definitions
│ └── utils # Utility functions and helpers
├── .env # Environment variables
├── .env.example # Example .env file
├── .eslintrc.js # ESLint configuration
├── .prettierrc # Prettier configuration
├── tsconfig.json # TypeScript configuration
└── package.json # Project dependencies and scripts
To contribute to this project, please fork the repository and create a pull request. Contributions are always welcome!
This project uses Prettier and ESLint to maintain code quality and consistency. Run the following command to format your code:
yarn formatEnsure that your code is type-safe by running:
yarn typecheckThis project is licensed under the MIT License. See the LICENSE file for details.
- GNews API - for providing the news data
- Express.js - the web framework used
- Swagger - for API documentation
- TypeScript - for static type checking
Happy coding!