Skip to content

Instantly share code, notes, and snippets.

@tpjnorton
Last active November 9, 2021 14:23
Show Gist options
  • Save tpjnorton/2d5f2288df65c6211e6ce4a129b15b7c to your computer and use it in GitHub Desktop.
Save tpjnorton/2d5f2288df65c6211e6ce4a129b15b7c to your computer and use it in GitHub Desktop.
A simple API route using next-api-decorators
import { createHandler, Post, Delete, Get } from '@storyofams/next-api-decorators';
import { requiresAuth } from './requires-auth.ts'
class ItemHandler {
@requiresAuth()
@Post()
async create() {
doSomething();
return { name: 'John Doe' };
}
@requiresAuth()
@Delete()
async delete() {
await doSomethingElse();
return { status: 'deleted' };
}
@Get()
list() {
return await doAThirdThing();
}
}
export default createHandler(ItemHandler);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment