qubic-api
v1.5.135
Published
type-safe apis for nextjs
Downloads
41
Readme
Introduction
Type-safe APIs for NextJS
Usage
import {EHttpStatusCode} from "qubic-api";
import { api } from "qubic-api";
/* global handler */
export const secure = api<{ user: { name: string } }>(async (req, res) => {
if (req.headers.authorization !== "abc") return EHttpStatusCode.BadRequest
// non-status code return is implicit succes.
})
/* in your endpoints */
export default secure({
GET: (req, res) => Promise.resolve("hello world"), // must be a Promise.
POST: async (req, res) => db.users()
});