Brought into line with JWT protocol

Resolved #2
This commit is contained in:
2021-03-07 13:53:29 +11:00
parent f919af4248
commit 67a1c744ae
20 changed files with 479 additions and 335 deletions
+28 -30
View File
@@ -4,12 +4,24 @@ An API centric news server. Uses Sequelize and mariaDB by default.
# Setup
This currently runs in docker. It might need to run twice the first time.
There are multiple ways to run this app - it can run on it's own via `npm start` (for production) or `npm run dev` (for development). it can also run inside docker using `docker-compose up --build` - run `node configure-script.js` to generate docker-compose.yml.
To generate an authorization token, use [auth-server](https://github.com/krgamestudios/auth-server). A public-facing development auth-server is available here (tokens are 10 minutes):
```
POST https://dev-auth.eggtrainer.com/auth/login HTTP/1.1
Content-Type: application/json
{
"email": "kayneruse@gmail.com",
"password": "helloworld"
}
```
# API
```
//NOTE: GET will return null if a specific article can't be found
//NOTE: GET will return an empty array if a specific article can't be found
//NOTE: you can add a "limit" query parameter to change the default limit
GET /news?limit=10
@@ -33,11 +45,11 @@ GET /news/archive/:id
...
]
//get the latest titles, up to a default limit, or specify the index "id"
GET /news/titles/:id
//get the latest metadata, up to a default limit, or specify the index "id"
GET /news/metadata/:id
//get the titles starting from the beginning, up to a default limit, or specify the index "id"
GET /news/archive/titles/:id
//get the metadata starting from the beginning, up to a default limit, or specify the index "id"
GET /news/archive/metadata/:id
//result (if only a single article is specified, returns just that article rather than an array):
[
@@ -54,50 +66,36 @@ GET /news/archive/titles/:id
//send a formatted JSON object, returns new index on success, or error on failure
POST /news
Authorization: Bearer XXX
//arguments:
{
"key": key //the whitelist key, allows access to the POST routes
"title": title //title of the article
"author": author //author of the article
"body": body //body of the article
}
//result:
//result (status 200 on success, otherwise an error status):
{
"ok": ok //true on success, otherwise false
"index": index //new index of the article, or undefined
"error": error //error encountered, or undefined
"index": index //new index of the article
}
//similar to `POST /news`, but allows overwriting an existing article
PATCH /news/:id
Authorization: Bearer XXX
//arguments:
{
"key": key //the whitelist key, allows access to the PATCH routes
"title": title //title of the article
"author": author //author of the article
"body": body //body of the article
"title": title //title of the article, optional
"author": author //author of the article, optional
"body": body //body of the article, optional
}
//result:
{
"ok": ok //true on success, otherwise false
"error": error //error encountered, or undefined
}
status 200 on success, otherwise an error status
//remove an article from the news feed
DELETE /news/:id
Authorization: Bearer XXX
//arguments:
{
"key": key //the whitelist key, allows access to the DELETE routes
}
//result:
{
"ok": ok //true on success, otherwise false
"error": error //error encountered, or undefined
}
status 200 on success, otherwise an error status
```