dnaeon / cl-jingle

Common Lisp web framework with bells and whistles (based on ningle)
Other
48 stars 5 forks source link

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

Open sheepduke opened 1 year ago

sheepduke commented 1 year ago

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?

dnaeon commented 1 year ago

Hey @sheepduke ,

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