Wrong 404 when post data is wrong. Should be 400
See original GitHub issueI 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:
- Created 6 years ago
- Comments:6 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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…
Ok, thanks for clearing it out!