Skip to content

SourceCodeOER/sourcecode_api

Repository files navigation

Source Code API codecov Codacy Badge Greenkeeper badge

the new open source catalogue of computer exercises

Like Open Educational Resources, Source Code offers the possibility for educational teams to collaborate on the problem of creating and sharing exercises.
The latter consists in referencing IT resources, by allowing a diverse audience to benefit from all contributions.
As the catalogue expands, it will become an essential resource for all.

Requirements

  • PostgreSQL 12
  • Node.js 10+

Documentation

For more examples and API details, see API documentation (or build it yourself !)

Set up

  1. Install dependencies
npm install
  1. Creates a database (settings are stored in config/config.js)
npx sequelize db:create
  1. Creates the schema exercises_library in this database and
    Apply all Sequelize migrations to let Sequelize initialize your models in database :
npm run setUp

How do I populate the database quickly with my exercises ?

This API is delivered with a very complete CLI tool to handle the different possible situations. You will find more information on its documentation.

Starting the API

npm start

This will start the API that you reach on http://localhost:3000.

How to generate ... ?

Clients

Using openapi-generator :

npx openapi-generator generate -g typescript-axios -i api.yml -o out

Documentation

Using redoc-cli:

npx redoc-cli bundle api.yml -o docs/index.html

How to validate API documentation ?

Using openapi-generator :

npx openapi-generator validate -i api.yml

A single yaml file that contains all the API (Useful for Postman for instance) ?

Using speccy :

npx speccy resolve api.yml -o spec-output.yaml

Environment variables

You can customize some parts of the API using the following environment variables :

Environment variable name Purpose Default value
PORT The port to use for the API 3000
TOKEN_TTL A zeit/ms string that expresses in how much time a JWT token should expire '1h'
SECRET_PHRASE The secretOrPrivateKey for jwt.sign "Super secured passphrase"
DEBUG To print relevant logs using debug. Currently, you have the following choices :

- sourcecode_api:error_handler : Print all errors
- sourcecode_api:error_tracker : Print only failed requests errors
- sourcecode_api:files : Print only files that couldn't deleted
- sequelize:* : Print sequelize logs
...
DATABASE_URL The postgresql connection URI ( See postgresl docs for more information )
DATABASE_SCHEMA The schema we want to use on the database