https://github.com/diegovictor/functional-api
Study Case API with SOLID and no OOP
https://github.com/diegovictor/functional-api
api api-rest dependency-injection firebase firestore functional-api javascript jest js microservices node nodejs tests ts typescript
Last synced: about 2 months ago
JSON representation
Study Case API with SOLID and no OOP
- Host: GitHub
- URL: https://github.com/diegovictor/functional-api
- Owner: DiegoVictor
- License: mit
- Created: 2022-03-22T23:13:44.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-02-15T03:19:48.000Z (5 months ago)
- Last Synced: 2025-03-05T08:42:42.878Z (4 months ago)
- Topics: api, api-rest, dependency-injection, firebase, firestore, functional-api, javascript, jest, js, microservices, node, nodejs, tests, ts, typescript
- Language: TypeScript
- Homepage:
- Size: 1.18 MB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Functional API
[](https://ci.appveyor.com/project/DiegoVictor/functional-api)
[](https://firebase.google.com/)
[](https://firebase.google.com/)
[](https://babeljs.io/)
[](https://prettier.io/)
[](https://nodemon.io/)
[](https://eslint.org/)
[](https://github.com/airbnb/javascript)
[](https://jestjs.io/)
[](https://www.typescriptlang.org/)
[](https://app.codecov.io/gh/DiegoVictor/functional-api)
[](https://raw.githubusercontent.com/DiegoVictor/functional-api/main/LICENSE)
[](http://makeapullrequest.com)
[](https://insomnia.rest/run/?label=Functional%20API&uri=https%3A%2F%2Fraw.githubusercontent.com%2FDiegoVictor%2Ffunctional-api%2Fmain%2FInsomnia_2024-11-28.json)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](https://github.com/DiegoVictor/named-api) and [Named Web](https://github.com/DiegoVictor/named-web).## Table of Contents
* [Requirements](#requirements)
* [Installing](#installing)
* [Firebase](#firebase)
* [Service Account](#service-account)
* [Script](#script)
* [Development](#development)
* [Usage](#usage)
* [Deploy](#deploy)
* [Routes](#routes)
* [Running the tests](#running-the-tests)
* [Coverage report](#coverage-report)# Requirements
* Node.js ^18.19.0
* Firebase Account
* [Functions](https://firebase.google.com/docs/functions)
* [Firestore](https://firebase.google.com/docs/firestore)# Installing
Easy peasy lemon squeezy:
```
$ yarn
```
Or:
```
$ npm install
```
> Was installed and configured the [`eslint`](https://eslint.org/) and [`prettier`](https://prettier.io/) to keep the code clean and patterned.## Firebase
First, [create a project into Firebase](https://firebase.google.com/docs/android/setup#create-firebase-project), then [create a database](https://firebase.google.com/docs/firestore/quickstart).### Service Account
Create a service account:* [Service Account](https://console.firebase.google.com/project/_/settings/serviceaccounts/adminsdk?authuser=0)
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](https://firebase.google.com/pricing?authuser=0&hl=pt).## 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](https://jestjs.io/) 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.