Going Serverless Part 2 – Building a REST API with No Servers
November 10, 2019
This post continues the exploration of serverless by showing how to create a REST API using serverless functions.
What Is Serverless?
Serverless doesn't mean there's no server. It means:
- You don't manage the server.
- You write functions that respond to HTTP events.
- They scale automatically and only run when called.
Example Project: Guestbook API
Create an API to:
GET /entries
– fetch all guestbook entriesPOST /entries
– add a new entry
Option 1: Netlify Functions
1. Setup
npm install netlify-cli -g
netlify init
netlify functions:create
Create a file at netlify/functions/entries.js
:
exports.handler = async (event) => {
if (event.httpMethod === "GET") {
return {
statusCode: 200,
body: JSON.stringify([{ name: "Luiz", message: "Great blog!" }]),
};
}
if (event.httpMethod === "POST") {
const data = JSON.parse(event.body);
return {
statusCode: 201,
body: JSON.stringify({ saved: true, data }),
};
}
return { statusCode: 405 };
};
Run locally:
netlify dev
Call from front-end with fetch:
fetch("/.netlify/functions/entries")
.then(res => res.json())
.then(data => console.log(data));
Option 2: AWS Lambda + API Gateway
This requires more setup, but is useful for production:
- Use AWS SAM or Serverless Framework
- Define function handler and route via API Gateway
- Deploy with AWS CLI
Benefits
- No server provisioning or maintenance
- Scales automatically
- Pay per request
- Works well with static frontends (like JAMstack sites)
Serverless is more than just a trend. It’s a solid way to build real APIs without the weight of traditional backend stacks.
Recent posts
- At-Least-Once vs. Exactly-Once - Understanding Message Delivery Guarantees
June 12, 2025
Learn about message delivery guarantees in distributed systems. Understand why most production systems implement at-least-once delivery with idempotency rather than attempting exactly-once delivery.
- How Idempotency Saves Your API from Chaos
June 11, 2025
Learn how to implement idempotency in your APIs to prevent duplicate actions and ensure data consistency. Includes practical examples with Supabase and Node.js.
- Vibe Coding ‑ Notes from the First Try
June 6, 2025
Quick lessons from spinning up a new blog with an AI pair‑programmer and Cursor.