Created
September 3, 2022 14:27
-
-
Save skolhustick/bf59cd68fd2814cf85a685b0b5833737 to your computer and use it in GitHub Desktop.
astro-mongodob-api.users.js
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
// src/pages/api/users.js | |
import { createUser, getAllUsers } from "../../lib/users"; | |
export const get = async () => { | |
const users = await getAllUsers(); | |
if (!users) { | |
return new Response(null, { | |
status: 404, | |
statusText: "Not found", | |
}); | |
} | |
return new Response(JSON.stringify(users), { | |
status: 200, | |
}); | |
}; | |
export const post = async ({ request }) => { | |
const newUser = await request.json(); | |
const user = await createUser(newUser); | |
return new Response(JSON.stringify(user), { | |
status: 200, | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment