Skip to content

DiegoVictor/functional-api

Repository files navigation

Functional API

AppVeyor firebase babel prettier nodemon eslint airbnb-style jest typescript coverage MIT License PRs Welcome
Run in Insomnia

Study Case to figure out a simple way to have dependency injection and dependency inversion principle using only functions (not classes here, sorry OOP guys).

This API makes usage of a external service that generates random names, see more in: Named API and Named Web.

Table of Contents

Requirements

Installing

Easy peasy lemon squeezy:

$ yarn

Or:

$ npm install

Was installed and configured the eslint and prettier to keep the code clean and patterned.

Firebase

First, create a project into Firebase, then create a database.

Service Account

Create a service account:

Then save it in src\config\service-account.json.

Script

There is a script (scripts/main.js) that setup a feature flag required by the application, to run:

$ node scripts/main.js

Now your are ready to go

Development

Improve the development velocity running the watch script to rebuild the project everytime a file in src folder changes.

npm run watch

Or:

yarn watch

Then you can just run the serve script once.

Usage

Run the build script:

npm run build

Or:

yarn build

Then you are ready to start the server:

npm run serve

Or:

yarn serve

Deploy

npm run deploy

Or:

yarn deploy

Deploy the functions is very easy, but is requires a Blaze (pay-as-you-go) plan.

Routes

route HTTP Method params description
/featureFlags GET - Returns all flags in the database.
/featureFlags/:key GET key of the flag. Returns the specified flag.
/randomNames GET - Returns random names in raw text or in base64 format (depends if the flag is enable or not).

Running the tests

Jest was the choice to test the app, to run:

$ yarn test

Or:

$ npm run test

Run the command in the root folder

Coverage report

You can see the coverage report inside tests/coverage. They are automatically created after the tests run.