Giter Site home page Giter Site logo

caracal's Introduction

Caracal.

Node.js based API

This API is based on express and mongodb . Swagger is being used to for API documentation and validation.

It makes use of JSON config-maps with an opinionated architecture.

app.js Responsible for app bootstrap. This file first loads the configuration from config-map using configurationAdaptor.js. Once config is loaded, it makes the connection with database. After that, it actually starts the server.

server.js contains the code for server initiation. It exposes a function which actually starts the servers and make it listen on the specified port. It also contains the necessary middlewares. required for processing the requests.

Folder Structure

  • api

    • adaptors -> responsible for creating connections to external APIs and Databases
    • controllers -> responsible the handling the request/response after the validation
    • db-> responsible to starting the db, initializing the schemas
    • helpers -> helper functions for data manipulation (called mostly by controller)
    • models -> models and schema files for entities
    • swagger -> swagger API documentation and validation
    • utils -> wrapper for utilities like http-client, momentjs, jwt, crypto, etc.
  • config

    • config.js -> file to basic config info like app-name, port, etc.
    • configurationAdaptor -> file to load and parse the config map
    • appSettings.json -> JSON config-map
  • app.js - app bootstrap (load config map, start db, start server)

  • server.js - server specific code, middleware, etc.

Steps to start the server

  • Start the mongodb server

  • Put the mongodb uri in '../config/appSettings.json'

  • Run the server using the following command

    • APP_SETTINGS_FILE_PATH="<<path to appSettings.json>>" node app.js
    • Please provide a valid path in above line depending on the operating system.
    • for example: C:\Users\xyz\caracal\config\appSettings.json
    • APP_SETTINGS_FILE_PATH is an environment variable which holds the path to our config map.
  • If you use VS Code, you can directly launch the program from Debug window (launch config already pushed)

API Documentation

To view the the API documentation, Download the HTML file from https://gist.github.com/tarusharora/d9c371a7ebf745ecdccf208ffc61f29d OR just copy the contents of swagger.yaml to editor.swagger.io

Why Swagger?

Swagger is mainly used for API contract, documentation, and basic validation.

Next steps

  • Use of robust api validation libraries like joifor complex validation
  • Logging of each incoming/outgoing request and response with timings - Incoming Request to Node Server - Outgoing Request to DB/Third party API - Incoming Response from DB/Third party API - Outgoing Response from Node server
  • Dockerizing the app
  • Deployment to any cloud provider

Sample Data

exported data of categories and products https://gist.github.com/tarusharora/7a9c587e7a27ec0172db0665c4948271 https://gist.github.com/tarusharora/6e319139ca72aa02a65c9458f3ba263b

Postman Collection

https://www.getpostman.com/collections/464db8ed748bae47fdec Note: this postman collection is only applicable for above-mentioned sample dataset as it contains some hardcoded objectids.

caracal's People

Contributors

tarusharora avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.