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.

Wrong 404 when post data is wrong. Should be 400

See original GitHub issue

I don’t know what I’m doing wrong, for me it seems that nothing is different from the kweet sample post on login, but when my app configured like this:

@location("/api/accounts")
class PostAccountRequest

fun Route.createAccount() {
    post<PostAccountRequest> {
        call.respondText("Are you trying to create an account?")
    }
}

it works:

$ curl -X POST localhost:8080/api/accounts -d '{"name":"thales","lastName":"machado"}'
Are you trying to create an account?

But when adding data to PostAccountRequest it starts giving me 404:

@location("/api/accounts")
data class PostAccountRequest(val name: String = "", val lastName: String = "")

fun Route.createAccount() {
    post<PostAccountRequest> {
        call.respondText("Are you trying to create an account?")
    }
}

The response:

$ curl -X POST localhost:8080/api/accounts -d '{"name":"thales","lastName":"machado"}'
<H1>404 Not Found</H1><P>Cannot find resource with the requested URI: /api/accounts</P>

Can someone help me on what I’m doing wrong here?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
orangycommented, Jul 23, 2017

Locations are strongly typed hrefs, if you wish. See some examples like https://github.com/Kotlin/ktor/blob/master/ktor-samples/you-kube/src/you/kube/Videos.kt#L39

I need to write a ktor.io article on this…

0reactions
thalescmcommented, Jul 23, 2017

Ok, thanks for clearing it out!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Should a RESTful API return 400 or 404 when passed an ...
5: 10.4.1 400 Bad Request The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat...
Read more >
How to Fix a 400 Bad Request Error (Causes and Fixes) - Kinsta
The 400 Bad Request error indicates that the server cannot or process the request due to a client error. Read about the common...
Read more >
Status Code 400 (Bad Request) Explained & How to fix it - Ryte
The 400 (Bad Request) status code indicates that the server cannot or will not process the request due to something that is perceived...
Read more >
How to Fix a 400 Bad Request Error: 8 Easy Methods
Stuck with a 400 bad request error? Read this article to find out 8 simple methods to solve the problem and its possible...
Read more >
Should we return a HTTP 404 or 400 for a customer record ...
Or a little longer: be as specific as you can. As you have alreay written yourself, a 404 is "not found", and the...
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