Skip to content

Latest commit

 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

news-restapi

Overview

A simple JSON REST API for a News channel. Pure python, no dependencies.

Requires Python 3.7 or higher and sqlite3 installed.

Data models

News

{
   "id":1,
   "created_date":"2019-11-18 22:49:06.885453",
   "modified_date":"2019-11-18 22:49:06.885453",
   "title":"News title",
   "content":"News content"   
}

Comment

{
   "id":1,
   "created_date":"2019-11-18 22:49:06.885453",
   "modified_date":"2019-11-18 22:49:06.885453",   
   "content":"Comment content"
}

API

GET|POST http://localhost:8080/news/
GET|PUT|DELETE http://localhost:8080/news/:id/

GET|POST http://localhost:8080/news/:news_id/comments/
GET|PUT|DELETE http://localhost:8080/news/:news_id/comments/:id/

Run

# create database
./db/create_db.sh

# run server
python start_server.py

Usage examples

curl -X POST -d '{"title": "News title", "content": "News content"}' "http://localhost:8080/news/"
curl -X GET "http://localhost:8080/news/"
curl -X PUT -d '{"title": "News updated title", "content": "News updated content"}' "http://localhost:8080/news/1/"
curl -X DELETE "http://localhost:8080/news/1/"

curl -X POST -d '{"content": "Comment"}' "http://localhost:8080/news/1/comments/"
curl -X GET "http://localhost:8080/news/1/comments/"
curl -X PUT -d '{"content": "Updated comment"}' "http://localhost:8080/news/1/comments/1/"
curl -X DELETE "http://localhost:8080/news/1/comments/1/"

Tests

python -m unittest discover -s news_restapi -p tests.py

About

A simple REST API for a News channel. Pure python, no dependencies.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages