question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Router post does not work.

See original GitHub issue

Hi,

I am new to deno and oak.

The below code doesnt work for post method but WORKS for get.

import { Application, Router } from "https://deno.land/x/oak/mod.ts";

const router = new Router();
router
  .post("/", context => {
    context.response.body = "Hello world Johnson!";
  });

const app = new Application();
app.use(router.routes());
app.use(router.allowedMethods());

await app.listen("127.0.0.1:8000");

Any thoughts on this? Thanks in advance.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12

github_iconTop GitHub Comments

1reaction
wthocommented, Feb 6, 2020

Just to add a small detail to the explanation: If you put a URL in any browser’s URL Bar, it will always run GET against that URL endpoint. To run POST you need to use a form submit or an ajax call. Cheers!

1reaction
linhub15commented, Feb 6, 2020

Let me elaborate on @wujingquan’s suggestion, correct me if I’m wrong. If you want to submit a post request in a browser you need to

  1. Run your code
  2. Create a file called index.html with this content and open it in a browser
<!-- index.html -->
<!DOCTYPE html>
<html>
<body>
<form action="http://127.0.0.1:8000" method="post">
  <input type="submit" value="Submit">
</form>
</body>
</html>
  1. Click the button

Navigating to http://127.0.0.1:8000 in any browser will only send GET requests and you can’t test the POST functionality of your code.

For more on HTTP requests check out MDN - HTTP request methods.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Express router not working for post requests - Stack Overflow
when I try to access localhost:8000/api/users it returns a 404 error. You don't have a GET route to localhost:8000/api/users , you have a ......
Read more >
Node js post request in route is not working - Treehouse
so im trying to get a program that im working on to use a simple post route request. Now in the program im...
Read more >
Handle GET and POST Request in Express - CodeForGeek
When the user clicks on the log-in button on the HTML page we will POST the request to Server and get the response....
Read more >
5.x API - Express.js
A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body ), or an empty...
Read more >
Express Tutorial Part 4: Routes and controllers - MDN Web Docs
The routes are defined either using .get() or .post() methods on the router object. All the paths are defined using strings (we don't...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found