0.1.10 • Published 4 years ago

awesome-express-api v0.1.10

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

Awesome-Express-Api

Overview

Features

-
-

Table of contents

Requests

Resources

Serializer

Models

Errors

Installation

npm i awesome-express-api

Initialize

import Express from 'express';
import AwesomeExpressApi from 'TODO'

const app = Express();
const pocInstance = new AwesomeExpressApi(app, DatabaseLayer, options);

// Register resources
pocInstance.addResource('customer')

// Start server
pocInstance.startServer();

Options

interface OptionsInterface {
    resetDatabase?: boolean,
    listRoutes?: boolean,
    port?: number,
    filterQueryFormat?: string,
    filterKey?: string,
    searchKey?: string,
    searchQueryFormat?: string,
    sortKey?: string,
    pageSizeKey?: string,
    pageNumberKey?: string,
    pageStartNumber?: number,
    sort?: { [keyName: string]: string },
    populateAfterPatchPost?: boolean,
    responseBuilder?: ResponseBuilderInterface
}

Custom response format at get route

The standard response format for a get route is a array with result objects. If you want additional fields in the response, you can specify a response builder and customize the response.

For usage pass a function with the following format to the responseBuilder-option:

function responseBuilder(req, databaseResult, filter, search)

Example

async function responseBuilder(req, result, filter, search) {
    const totalCount = await req.currentModel.model.countDocuments({...filter, ...search})
    const notFilteredTotalCount = await req.currentModel.model.countDocuments({})
    return {
        items: result,
        totalCount,
        notFilteredTotalCount
    }
}

const pocInstance = new AwesomeExpressApi(app, DatabaseLayer, {
    responseBuilder: responseBuilder
});

Validators

The following validators are available at the moment:

  • isString
  • minLength:NUMBER
  • maxLength:NUMBER
  • notEmpty
  • isBoolean

Access in requests

DatabaseLayer

Docker

Login to github docker to build and push new images

docker login docker.pkg.github.com -u USERNAME -p PRIVATETOKEN

Build new Image

- docker build -t docker.pkg.github.com/bobo-le/awesome-express-api/aea:TAG .
- docker push docker.pkg.github.com/bobo-le/awesome-express-api/aea:TAG

Kubernetes

Create a deployment with pods and service inside

kubectl create -f deployment.yaml

Update running pods with new image

kubectl set image deployment/DEPLOYMENTNAME LABELNAME=docker.pkg.github.com/bobo-le/awesome-express-api/aea:TAG --record

Scale Pods

- kubectl scale --replicas=COUNT -f deployment.yaml
- COUNT=0 menas stopping all

Apply new config

kubectl apply -f deployment.yaml

Create secret to pull image from private registry

- kubectl create secret docker-registry regcred --docker-server=docker.pkg.github.com --docker-username=USERNAME --docker-password=PRIVATETOKEN --docker-email=EMAIL
- "regcred" is the name of your secret. Used in deployment.yaml

Get URL for running service

- minikube service SERVICENAME --url
- the api is under this url reachable

Helm

When using helm, kubecl -f FILES doesnt work anymore out of the box. Instead use the following

Optionally using kubectl -f FILES

- helm template REPONAME -x .\templates\deployment.yaml
- this renders the template file with the correct values
- result can be piped to -f with the following line
- helm template REPONAME -x .\templates\deployment.yaml | kubectl -f -

Installing environment with helm

- helm install --name REPONAME HELMDIRECTORY
- the repo is available under the REPONAME property

Upgrading with helm

- helm upgrade REPONAME HELMDIRECTORY
- it uses rolling update
0.1.10

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.18

5 years ago

0.0.17

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago

0.0.0

5 years ago