Last active
November 9, 2021 14:23
-
-
Save tpjnorton/2d5f2288df65c6211e6ce4a129b15b7c to your computer and use it in GitHub Desktop.
A simple API route using next-api-decorators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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