Install package:
yarn add nuxt-nitro-helpers
# or
npm install nuxt-nitro-helpers
// ./servers/api/posts.ts
import { useRoute } from "nuxt-nitro-helpers";
export default useRoute({
get() {
return "GET /posts";
},
post(_, res) {
res.statusCode = 201;
return "POST /posts";
}
});
// ./servers/api/me.ts
import { useGetRoute } from "nuxt-nitro-helpers";
export default useGetRoute(() => {
return "GET /me";
});
// ./servers/api/quotes.ts
import { useRoute } from "nuxt-nitro-helpers";
export default useRoute({
get() {
return "GET /quotes";
},
fallback(_, res) {
res.statusCode = 405;
return "Method Not Allowed";
},
});