Character API is a simple REST API to store and retrieve character documents.
I built this API mainly to investigate how to use Babel with Node and to explore the library Fluture. It is not meant to be used in a real environment, but rather as an exercise to build a minimally functional app using new concepts.
The setup for Babel includes the plugin for the pipeline operator proposal.
Character API has two end points, which accept requests in several methods:
/api/characters
GET
: Returns a paginated list of all the characters stored in the database. It accepts an optional query parameterpage
.POST
: It creates a new document in the database. It returns 400 if the document isn't formatted correctly.
/api/characters/:id
GET
: Returns a specific document from the database matching theid
provided or 404 if no such id exists.PUT
: Updates a specific document from the database matching theid
provided. It returns 404 if no such id exists or 400 if the document isn't formatted correctly.DELETE
: Deletes a specific document from the database matching theid
provided. It returns 404 if no such document exists.
All documents submitted via POST
and PUT
requests must include the following fields (though they can include more):
name
: astring
specifying the character's name.aliases
: anarray
indicating the character's aliases if any. It can be empty.feats
: anarray
indicating important achievements of the character. It can be empty.occupation
: astring
indicating the character's occupation.
To use this application you will need Node >= 12
Clone the project and install its dependencies:
git clone git@github.com:arturjzapater/character-api.git
cd character-api
npm i
Create a copy of the .env
file:
cp -a .env.example .env
Seed database:
npm run seed
Start the server in development mode:
npm run dev
test
: run unit teststest:watch
: run unit tests on watch modee2e
: run end-to-end testsdev
: run the server in development modebuild
: build the files with babelstart
: build and start the server in production modeseed
: add some mock data to the database