GithubHelp home page GithubHelp logo

lholmquist / opossum-with-functions Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nodeshift-blog-examples/opossum-with-functions

0.0 2.0 0.0 69 KB

License: Apache License 2.0

JavaScript 100.00%

opossum-with-functions's Introduction

Node.js HTTP Function

Welcome to your new Node.js function project! The boilerplate function code can be found in index.js. This function will respond to incoming HTTP GET and POST requests. This example function is written synchronously, returning a raw value. If your function performs any asynchronous execution, you can safely add the async keyword to the function, and return a Promise.

Local execution

After executing npm install, you can run this function locally by executing npm run local.

The runtime will expose three endpoints.

  • / The endpoint for your function.
  • /health/readiness The endpoint for a readiness health check
  • /health/liveness The endpoint for a liveness health check

The parameter provided to the function endpoint at invocation is a Context object containing HTTP request information.

function handleRequest(context) {
  const log = context.log;
  log.info(context.httpVersion);
  log.info(context.method); // the HTTP request method (only GET or POST supported)
  log.info(context.query); // if query parameters are provided in a GET request
  log.info(context.body); // contains the request body for a POST request
  log.info(context.headers); // all HTTP headers sent with the event
}

The health checks can be accessed in your browser at http://localhost:8080/health/readiness and http://localhost:8080/health/liveness. You can use curl to POST an event to the function endpoint:

curl -X POST -d '{"hello": "world"}' \
  -H'Content-type: application/json' \
  http://localhost:8080

The readiness and liveness endpoints use overload-protection and will respond with HTTP 503 Service Unavailable with a Client-Retry header if your function is determined to be overloaded, based on the memory usage and event loop delay.

Testing

This function project includes a unit test and an integration test. All .js files in the test directory are run.

npm test

opossum-with-functions's People

Contributors

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