This project uses a MySQL database. See the server/glossaryDB.sql
for a dump of the database.
Terms consist of the term itself and its definition. The database also holds the name of the contributor who created it (or last edited it), plus the creation date and the last edit date. Each term has a unique id
Term resources are associated with a specific term. They need the id
of the term they are associated with, plus a link
and a linktype
. The link type is either video
(for YouTube or other video resources) or web
for links to web sites. Finally each term resource has a language
property to identify the programming language.
The API uses JSON Web Tokens for authentication. The /contributor/login
function will return a token which is valid for one hour, and a user ID.
{
"auth": "eyJhbGciOiJIUz..",
"userid":userid
}
The client should return an Authorization
header containing the token for all operations that add/edit/delete terms or their resources. The header should look like this:
Authorization: Bearer "eyJhbGciOiJIUz.."
See https://www.digitalocean.com/community/tutorials/nodejs-jwt-expressjs for a tutorial on this kind of authentication.
The .env
file for the API server should look like this:
TOKEN_SECRET=
DB_HOST=localhost
DB_USER=user
DB_PORT=3306
DB_PASSWORD=password
DB_NAME= glossary
WEB_PORT=3000
USE_AUTH=true
The TOKEN_SECRET
is generated with
require('crypto').randomBytes(64).toString('hex')
The USE_AUTH
variable should be set to either true
or false
. If you set it to false
, the API will not use any authentication.
Adjust the other environment variables according to your system.
GET /terms
will return all terms as a JSON listPOST /terms/add
will insert a new term. Parameters areterm
,definition
, andcontributorId
(AUTH)POST /terms/update
will update a term. Parameters aretermid
,term
,definition
,contributorId
(AUTH)POST /terms/delete
will delete a term. Parameters aretermid
(AUTH)POST /terms/term
will return a single term with a given ID. Parameters aretermid
GET /term/resources
will return all resources associated with a term. Parameters aretermid
POST /terms/resources/add
will insert a new resource for a specific term. Parameters aretermid
,link
,linktype
(video
orweb
),language
(AUTH)POST /terms/resources/update
will update a resource for a specific term. Parameters areresourceid
,termid
,link
,linktype
(video
orweb
),language
(AUTH)POST /terms/resources/delete
will delete a resource. Parameters areresourceid
(AUTH)GET /contributors
will return a list of contributors (id, name and email) (AUTH)POST /contributor/login
checks the email and password of a contributor. Parameters areemail
,password
.POST /newContributor
adds a new contributor to the database. Parameters arename
,email
,region
,password
. (AUTH)
There are four tables:
admins
containing administrator users (no API functions yet)contributors
containing all the contributors.terms
containing all the terms. Terms require a valid contributorid
.term_resources
this table will allow a link to be associated with a term. It requires a termid
and alinktype
which is eithervideo
orweb
.