Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

404 if I return response.body() #187

Closed
kliakos opened this issue Aug 21, 2014 · 7 comments
Closed

404 if I return response.body() #187

kliakos opened this issue Aug 21, 2014 · 7 comments

Comments

@kliakos
Copy link
Contributor

kliakos commented Aug 21, 2014

Hi, why do I get a 404 if I do this?

get("hello", (request, response) -> {
    response.body("Hello");

    return response.body();
});
404 Not found
The requested route [/hello] has not been mapped in Spark
@perwendel
Copy link
Owner

You don't explain how you try to access the resource. Have you tried adding a slash before hello ie.

get("/hello", (...

@kliakos
Copy link
Contributor Author

kliakos commented Aug 21, 2014

Yes, I have tried both paths, "hello" and "/hello". When I access http://localhost:4567/hello, I get the 404 in both cases

@perwendel
Copy link
Owner

The code inside your method is strange, however that doesn't explain the behavior. Are your running it standalone or in another web app server like tomcat? Have you tried just returning "Hello World";?

@kliakos
Copy link
Contributor Author

kliakos commented Aug 21, 2014

If I return any other string, it works fine. If I return the response.body()(which is a String), it gives the 404.

I am running this simple test with the built in Jetty container.

@perwendel
Copy link
Owner

This is because calling response.body() the invocation in ResponseWrapper is not delegated. I'm not sure why this is not done. However, It's not encouraged to use body(string) from Routes since the return value is used. It's supposed to be used from the filters where the return type is Void.

@kliakos
Copy link
Contributor Author

kliakos commented Aug 21, 2014

Clear enough.

Reading the http://www.sparkjava.com/readme.html#title4 you get the impression that this is the standard way you define the response body.

From code examples thought it is pretty clear that the example I have mentioned is never used and discouraged.

You can close this issue if you want.

@perwendel
Copy link
Owner

Yep, I might need to clarify that section and also fix the bug so it can be used from within Routes. I hope all the other documentation in the README section inspires users to use the return value.

perwendel added a commit that referenced this issue Nov 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants