Giter Site home page Giter Site logo

mock-api's Introduction

Serverless Mock API

This is a very simple serverless AWS application that runs on AWS gateway. It's designed as a mock API service, speeding up the development / testing of your web applications without relying on the completion of backend APIs.

Requirements

The following services and tools are used to run our mock API service.

Create the ACM certificate in the region you are deploying in (in my case, ap-southeast-2).

Deployment

The entire API serice can be deployed via CLI by following the instructions below.

Pre-Requisites

Create a copy of .env_example named as .env and replace the variables.

Deployment

Deploy the API into your AWS account

source .env
cd mock-api
sls deploy --region ap-southeast-2

Grab the MockApiDomain output value from Cloudformation, and then create CNAME entries under your domain. This can be done as either *.api.example.com or test.api.example.com + test2.api.example.com. The output can be grabbed by using the AWS cli command below (replacing mock-api-dev if you have replaced this with custom stack name).

aws cloudformation describe-stacks --stack-name "mock-api-dev" --region ap-southeast-2 --query "Stacks[0].Outputs[*].{Key: OutputKey, Value: OutputValue}" --output table

Configuring Data

A DynamoDB table will be created, where you can craft HTTP responses based on the following fields:

Column Type Description
Hostname String The HTTP host your API will respond on
Path String The HTTP URL your API will respond on
Auth Boolean Whether the Authorization header is required
Data Map A JSON object with data to respond with

Insert rows into your table and start hitting the API paths you have setup.

Requesting Data

You will now be able to send HTTP requests to your configured URIs. For troubleshooting purposes, the API will return the hostname and path you hit upon failure:

[sktan@devbox ~]$ curl -s https://test.api.example.com/test | jq
{
  "Errors": [
    "page not found"
  ],
  "Path": "/test",
  "Hostname": "test.api.example.com"
}

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.