Git Product home page Git Product logo

crmapi's Introduction

CRM REST API code example - Novak Zaballa

The scope of this sample code project is users and customers management of a CRM.

This project has been built with Serverless Framework and targeting AWS lambda with Node.js + DynamoDB. You can deploy the proyect to AWS installing and configuring serverless, or you can run the services locally, using the serverless-offline plugin, which is included. The offline configuration also includes a local DynamoDB instance is provided by the serverless-dynamodb-local plugin.

Setup and test locally

To test your service locally, without having to deploy it first, you will need node.js (tested with v13.7.0) and follow the steps below in the root directory of the project.

npm install
serverless dynamodb install
serverless dynamodb start --migrate

The --migrate option creates the schema. Ctl+C to stop the local DynamoDB. The DB schema and data will be lost since by default the local DB is stored in memory.

Run service offline

To test the project locally use:

serverless offline start

Alternatively you can debug the project with VS Code. This repository includes the launch.json file needed by VS Code to run and debug this serverless project locally. How ever dynamodb needs to be started.

Configure and Deploy service to AWS

For production you will need to configure authetication the OAuth 2 provider. Replace the file oauth2_public_key.pem in the root directory with the right public signature PEM file. Also cnfigure the file secrets.json with the corresponding OAUTH_AUDIENCE value.

To deploy the service you need an account in AWS. Use the following command:

serverless deploy -v

Authorization for testing

Every request must include an authorization header containing the OAuth Bearer token. For testing purposes currently an Auth0 account is in use, The request content type must be application/json as per the examples below. While in dev stage, I will provide valid access token of quarklap user (with only customer priveleges and not users admin permissions) via slack channel.

Live Demo

You can test locally following the former instructions, however it is also a live test with the following endpoints published in my AWS account for testing purposes:

Authenticate User Credentials And get Access Token

Email address and password for testing purposes will be shared through email or slack.

User Management

Customer Management

Live Testing with Swagger UI

Click here to see API documentation and test iit n Swagger UI

Usage Examples

You can test locally the create, list, update, or delete customers endpoints of the CRM using postman or curl commands using the following payload exmaples: (currently only is implemented the add and modify customers endpoint).

Create a Customer (Validation implemented)

Example Succesfull Request Payload:

{
"Name":"Paul Ray",
"Surname":"Ghost",
"Phone":"(122)23878 343",
"Email":"[email protected]",
"Age":16
}

Example Result (Status 200 - OK):

{
"GroupId": "4",
"CustomerId": "4532324",
"Name": "Paul Ray",
"Surname": "Ghost",
"Age": 16,
"Email": "[email protected]",
"Phone": "(122)23878 343",
"CreateUser": "HardcodedTestUser",
"CreateDate": "2020-04-16T03:51:37.626Z"
}

Example Rejected Request Payload:

    {
      "Name":"John",
      "Surname":"Wayne",
      "Phone":"(123) 22388 765",
      "Email":"jwaynemidominio.com",
      "Age":2
}

Example validation error result (Status 400 - Bad Request):

[
    {
        "target": {
            "CustomerId": 3644565,
            "Name": "John",
            "Surname": "Wayne",
            "Phone": "(123) 22388 765",
            "Email": "jwaynemidominio.com",
            "Age": 2,
            "CreateDate": "2020-04-16T11:34:53.636Z",
            "CreateUser": "HardcodedTestUser"
        },
        "value": 3644565,
        "property": "CustomerId",
        "children": [],
        "constraints": {
            "isString": "CustomerId must be a string"
        }
    },
    {
        "target": {
            "CustomerId": 3644565,
            "Name": "John",
            "Surname": "Wayne",
            "Phone": "(123) 22388 765",
            "Email": "jwaynemidominio.com",
            "Age": 2,
            "CreateDate": "2020-04-16T11:34:53.636Z",
            "CreateUser": "HardcodedTestUser"
        },
        "value": 2,
        "property": "Age",
        "children": [],
        "constraints": {
            "min": "Age must not be less than 16"
        }
    },
    {
        "target": {
            "CustomerId": 3644565,
            "Name": "John",
            "Surname": "Wayne",
            "Phone": "(123) 22388 765",
            "Email": "jwaynemidominio.com",
            "Age": 2,
            "CreateDate": "2020-04-16T11:34:53.636Z",
            "CreateUser": "HardcodedTestUser"
        },
        "value": "jwaynemidominio.com",
        "property": "Email",
        "children": [],
        "constraints": {
            "isEmail": "Email must be an email"
        }
    }
]

crmapi's People

Contributors

novakzaballa avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  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.