How do I POST to the AtomPub API? #766
-
I would like sample code for POSTing to the AtomPub API. import { Handlers } from "$fresh/server.ts";
export default function Home() {
return (
<form method="post">
<button>
POST
</button>
</form>
);
}
export const handler: Handlers = {
async POST(req, ctx) {
console.log("POST");
return new Response("", {
status: 303,
headers: {
Location: "/",
},
});
},
}; |
Beta Was this translation helpful? Give feedback.
Answered by
lucacasonato
Sep 15, 2022
Replies: 2 comments 4 replies
-
Here's how I handle POST data. // some code up here
async POST(req, ctx) {
const db = deta.Base("kv");
const body = (await req.formData()).get("data") as unknown as DetaBaseValue;
const key = Math.random().toString(36).substring(2, 12);
const _item = await db.put({
...body,
}, key, {
expireIn: 604800,
});
return ctx.render(
new Response(JSON.stringify({
key: key,
success: true,
}), {
headers: {
"content-type": "application/json",
"status": "200",
},
}),
);
},
// some code down here Still has some stuffs to fix tho, and it's still spewing errors but you do |
Beta Was this translation helpful? Give feedback.
3 replies
-
To make outbound HTTP requests, use |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
ru88s
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To make outbound HTTP requests, use
fetch
.