Giter Site home page Giter Site logo

serverless-api's Introduction

serverless-api

This API was made with Serverless framework and Node.js. Since the scope was so small, I felt that setting up a test suite would be overkill and just decided to test manually.

It has 3 endpoints, 2 which are GET and 1 POST.

The first endpoint takes a JSON file body, and a Filename header must be provided with the filename.

Example:

File upload: request1 Header: request2 Valid json files:

{
  "latitude": 51.507351,
  "longitude": -0.127758
}
{
  "latitude": 59.507331,
  "longitude": 10.222355,
  "name": "ontario"
}

Invalid json files:

{
  "latitude": 51.507351,
  "name": "london"
}
{
  "latitude": 51.507351,
  "longitude: -900.000000
}
{
  "latitude": "new york city",
  "longitude: -900.000000
}

There are a couple of validations that the file must pass in order to store it in the S3 bucket:

  • File and filename must not be empty.
  • Filename must be .json extension.
  • It must be a valid json file.
  • It must have the mandatory fields latitude and longitude.
  • Latitude must be -90 < latitude < 90 and longitude must be -180 < longitude < 80.

The second endpoint is a simple get request without parameters that returns a list of all file names without the .json extension.

The third endpoint is another get request, but this time it only looks for a single object with the specifed key in the parameters, the key name is filename.

Example:

request3

All the code is in the API folder, with 3 subfolders, one is for the external route, which is the upload one. External which is for both location requests, and utils for various utility methods I abstracted to help me.

To run yourself (with NPM):

  1. Download project and navigate to it.

  2. Install serverless cli globally.

npm install -g serverless
  1. Configure serverless with AWS credentials, get your key and secret from your AWS account.
serverless config credentials --provider aws --key AKIAIOSFODNN7EXAMPLE --secret wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
  1. Install dependencies.
npm i
  1. Deploy with serverless.
serverless deploy
  1. Alternatively, you can run locally with serverless-offline.
serverless offline start

serverless-api's People

Contributors

edmildm avatar

Watchers

James Cloos 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.