Skip to content

Latest commit

 

History

History

bautajs-express-example

bautajs-express-example

  • This API example intends to show how you can use Bauta.js with Express.js.
  • This project example purpose is to showcase main features using simple examples.
  • This project example does not intend to show good practices using Node.js or security practices at all. Please be sure you follow security good practices on your Node.js API (i.e. adding helmet).

How to start

  • It is recommented that you are using node v18.
  • npm install from the root project of the monorepo
  • enter into packages/bautajs-express-example folder
  • run npm script npm run start

List of exposed Services

  • GET /api/articles
    • Returns a list of articles
  • GET /api/chuckfacts/{string}
    • Returns a list of chuckfacts from the string
    • Shows how to use the cache decorator in a resolver
  • GET /api/cats
    • Returns a list of cat facts
  • GET /api/minimap
    • Returns an object with all the defined key-values
  • GET /api/minimap/${key}
    • Returns an object with the found key-value.
  • POST api/minimap
    • Allows to store a key-value pair into the minimap
  • GET api/randomYear
    • Returns a string with a fact from a random year
  • GET api/randomYear2
    • Returns an object with a fact from a random year
  • GET api/factNumber/{number}
    • Returns a string with a random fact from the input number
  • GET api/factNumber2/{number}
    • Returns an object with a random fact from the input number
  • GET api/multiple-path/{key}
  • GET api/multiple-path/specific
    • These two endpoints help understand how the route ordering works
  • GET api/cancel/{number}
    • Returns a string if number is less than 10 seconds. Aborts after 10 seconds in the rest of the cases.

Custom Logger example

Out of the box bauta.js express example comes with the default logger. We provide a non default logger example in the file bauta-with-custom-logger.js.

If you want to use it, just modify server.js and change the require from bautaJS variable from current value to the custom-logger-bauta.js:

const bautaJS = require('./server/instances/bauta');

change it to:

const bautaJS = require('./server/instances/bauta-with-custom-logger');

With this change it a custom logger, defined in custom-logger-bauta.js, is used by bauta.js instead of the default one.

Third party dependencies licenses

Production