Zuplo logo
Back to all articles
March 24, 2022
5 min read

An API gateway over SaaS?

Josh Twist
Josh TwistCo-founder & CEO

This one's a little extra. Zuplo is so programmable you can use it in ways you've never considered for a gateway... a gateway over SaaS APIs - like AirTable.

Length: 2 minutes

In this example we use the Event Planning Template.

And here's the code in our request handler

import { ZuploContext, ZuploRequest, environment } from "@zuplo/runtime";

export default async function (request: ZuploRequest, context: ZuploContext) {
  const body = await request.json();

  const data = {
    records: [
      {
        fields: {
          Name: body.name,
          Email: body.email,
        },
      },
    ],
  };

  const response = await fetch(environment.ATTENDEES_URL, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${environment.API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify(data),
  });

  if (!response.ok) {
    return new Response("Error calling AirTable!", {
      status: 500,
    });
  }
  return new Response("Success", {
    status: 200,
  });
}

If you'd like to learn about other cool things an API gateway can do, check out our top API gateway features guide.

Questions? Let's chat

Join our community to discuss API integration and get help from our team and other developers.

OPEN DISCORD
51members online