Skip to content

firstandthird/macro-http-api

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

arc-macro-http

Forward compat path to migrate Architect to API Gateway to HTTP APIs from REST APIs.

Omg Why?!

  • HTTP APIs are faster
  • HTTP APIs are cheaper
  • New request payload is better for parsing multivalue headers and cookies
  • New response schema cleans up barfy boilerplate

Before:

exports.handler = async function http(req) {
  // req.headers.cookie (big string u need to parse)
  // req.multiValueHeaders.cookie (array of strings)
  return {
    isBase64Encoded: false,
    statusCode: 200,
    headers: { 
      'Content-Type': 'application/json' 
    },
    body: JSON.stringify({
      name: 'John Doe',
      message: 'hello',
    })
  }
}

After:

exports.handler = async function http(req) {
  // req.cookies 👍🏽
  return {
    name: "John Doe",
    message: "hello"
  }
}

Way more chill 🧊

Ok..How?!

Install:

npm i @architect/macro-http-api

And add to your arcfile:

@app
myapp

@macros
architect/macro-http-api

@http
get /

⚠️ Warning! you must return {statusCode, body, headers} if the payload is NOT application/json

That's it!

About

Architect macro that uses API Gateway HTTP APIs (instead of API Gateway REST APIs)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 91.0%
  • Arc 4.8%
  • HTML 4.2%