Project Setup
First create a Next project with:Javascript (fetch).
Implementation
Paste the producer code to thepages/api/hello.js as below:
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
This tutorial shows how to use Upstash Kafka with Next.js.
➜ kafka-examples git:(master) ✗ npx create-next-app@latest
✔ What is your project named? … getstarted-nextjs
Creating a new Next.js app in /Users/enes/dev/kafka-examples/getstarted-nextjs.
Javascript (fetch).
pages/api/hello.js as below:
export default function handler(req, res) {
fetch(
"https://full-mantis-14079-us1-rest-kafka.upstash.io/produce/newtopic/MESSAGE",
{
headers: {
Authorization:
"Basic Wm5Wc2JDMzUwYVhNdE1UUXlPVDlUR2szT0ZkanZlWUhCVjlKanpvdzAzU25VdFJROjQtUi1mbXRvYWxYbm9ldTlUalFG5qZlNLd0VzRTEwWXZITWlXNjNoRmxqcVVycnE1X3lBcTRUUEdkOWM2SmJxZlE9PQ==",
},
}
)
.then((response) => response.json())
.then((data) => {
console.log(data);
});
res.status(200).json({ name: "John Doe" });
}
npm run dev
{
"topic": "newtopic",
"partition": 0,
"offset": 281,
"timestamp": 1640993860432
}
Was this page helpful?