A simple Spring Boot REST API framework for fetching news articles.
API Documentation
| Endpoint | Params | Example |
|---|---|---|
| /search | q Keywords or phrases to search in the article title and body. Max length is 100 characters. Surround phrases with quotes ("") for exact match. Without ("") it will do an OR search. Alternatively you can use the AND / OR / NOT keywords, and optionally group these with parenthesis. Eg: crypto AND (ethereum OR litecoin) NOT bitcoin. searchIn (Optional) The fields to restrict your q search to. Possible values are title, description, content. Multiple options can be specified by separating them with a comma, for example: title,content. count (Optional) is an optional param with max limit of 100, default 10. | /search?q=apple%20tv&count=10, search?q=apple%20tv&searchIn=title&count=10, search?q="apple tv"&searchIn=title&count=10 |
| /search/top/{count} | count returns top n articles based on porpularity. Min count value is 1, maximum is 100 | /search/top/5 |
| /search/top/{category}/{count} | returns top n articles based on the popularity of the category passed. Possible categories business, entertainment, general, health, technology. count Min count value is 1, maximum is 100. | /search/top/business/5 |
Response Object
| Attribute Name | Description |
|---|---|
| articles | The results of the request |
| sourceId | The identifier id for the source this article came from |
| sourceName | The display name for the source this article came from |
| author | The author of the article |
| title | The headline or title of the article |
| description | A description or snippet from the article |
| url | The direct URL to the article |
| urlToImage | The URL to a relevant image for the article |
| publishedAt | The date and time that the article was published, in UTC (+000) |
| content | The unformatted content of the article, where available. This is truncated to 200 char |
- Install Maven
- Install git
- Install jdk 17
git clone https://github.com/khalsa/news-api.git
mvn clean install
mvn spring-boot:run
mvn test
curl http://localhost:8080/v1/news/search?q=samsung|json_pp
curl http://localhost:8080/v1/news/search/top/5|json_pp
curl http://localhost:8080/v1/news/search/top/business/5|json_pp
http://localhost:8080/swagger-ui/index.html
- Support more search features.
- Improve exception handling, make error messages more verbose.
- Move secret key used for encrypting api key to environment variables or vault.
- Containerize the application.
- Use distributed caching like redis.
- Implement retry logic while calling external api.
- Implement rate limiter.