This is a Django web application that retrieves data from Hacker News API and makes it easier to navigate the news items. It provides search and filter functionality and also enables clients, through three API endpoints, to create news items, modify and delete only the items they created and provide read-only access to news items generated from Hacker News API server.
The following technologies were used in this project:
Before starting, you need to have Git and Python installed.
Kindly ensure that you are in the root directory before running the following commands.
python3 -m venv env
. env/bin/activate
pip install -r requirements.txt
python manage.py makemigrations
python manage.py migrate
python manage.py collectstatic
python manage.py test
python manage.py shell < hn_api.py
Open another terminal window, activate the virtual environment and run the following command:
. env/bin/activate && python manage.py runserver 8080
The endpoints, expected payloads, and responses are described below.
GET api/v1/news/
curl -i -H 'Accept: application/json' http://127.0.0.1:8080/api/v1/news/
{
"message": "success",
"data": {
"news": [
[
{
"id": "c21b9f5f-72dd-4db7-8581-f49fcbba9087",
"title": "4nm Mac ‘M2’ chip to arrive in second of half of 2022, and ‘M2 Pro’ in 2023",
"author": "retskrad",
"type": "story",
"url": "https://9to5mac.com/2021/12/20/m2-m2-pro-chips-rumor/",
"text": "",
"score": 2,
"is_from_api": true
},
{
"id": "6793f01c-1ea0-409e-af2b-13785414368d",
"title": "A Food App Has Made Its First Delivery in Space",
"author": "rustoo",
"type": "story",
"url": "https://theswaddle.com/a-food-app-has-made-its-first-delivery-in-space/",
"text": "",
"score": 2,
"is_from_api": true
}
]
},
"errors": null
}
POST api/v1/add-news
curl -i -H 'Accept: application/json' http://127.0.0.1:8080/api/v1/add-news
{
"title": <String>,
"author": <String>,
"type": <String>
"text": <String>
"score": <Integer>
}
{
"message": "success",
"data": {
"news": {
"id": <UUID>,
"title": <String>,
"author": <String>,
"type": <String>
"url": <String>,
"text": <String>
"score": <Integer>,
"is_from_api": <Boolean>
}
},
"errors": null
}
GET api/v1/news/<id>
curl -i -H 'Accept: application/json' http://127.0.0.1:8080/api/v1/news/<id>
{
"message": "success",
"data": {
"news": {
"id": <UUID>,
"title": <String>,
"author": <String>,
"type": <String>
"url": <String>,
"text": <String>
"score": <Integer>,
"is_from_api": <Boolean>
}
},
"errors": null
}
PUT api/v1/news/<id>
curl -i -H 'Accept: application/json' http://127.0.0.1:8080/api/v1/news/<id>
{
"title": <String>,
"author": <String>,
"type": <String>
"text": <String>
"score": <Integer>
}
{
"message": "success",
"data": {
"news": {
"id": <UUID>,
"title": <String>,
"author": <String>,
"type": <String>
"url": <String>,
"text": <String>
"score": <Integer>,
"is_from_api": <Boolean>
}
},
"errors": null
}
DELETE api/v1/news/<id>
curl -i -H 'Accept: application/json' http://127.0.0.1:8080/api/vi/news/<id>
{
"message": "success",
"data": {
"news": {}
},
"errors": null
}