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

Provide helper function for returning a list of data? #3

Open
sheepduke opened this issue Mar 31, 2023 · 1 comment
Open

Provide helper function for returning a list of data? #3

sheepduke opened this issue Mar 31, 2023 · 1 comment

Comments

@sheepduke
Copy link

You know lack requires the response to be a pathname, a byte array, a single string or a list of (state headers content). Weirdly the content itself has to be a list. Despite that, what if you simply want to return a list of objects as result? If you directly return it from a route handler, it will be recognized by lack as the last case and an error is signaled.

I know the macro (jingle:with-json-response), but it is locked in jonathan. Also, I think it is better to handle JSON serialization in a middleware, just like how status codes like 404 are handled.

Having said that, what I did was writing a helper function to wrap the list data in a valid lack response list, then use a middleware to handle JSON serialization.

Do you have any idea about it? How can this part be made more dev-friendly?

@sheepduke sheepduke changed the title Provide helper function for returning a list of data Provide helper function for returning a list of data? Mar 31, 2023
@dnaeon
Copy link
Owner

dnaeon commented Mar 31, 2023

Hey @sheepduke ,

Feel free to propose changes by submitting a PR. I'd be happy to review and discuss it, thanks!

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