Closed jcoleman-techempower closed 5 years ago
You return a quoted list (here). This means that the content is not evaluated, so the value is never converted to json. You should change this line to something like (list 200 '(:content-type "application/json" :server "Woo") (jonathan:to-json '(:message "Hello, World!")))
(not tested).
As this is for a benchmark: This means that the list is consed every time the function is called, and the conversion is also done every time. If you want to compare the speed of woo you need to make sure that this overhead isn't too large.
@libre-man Could you point me in the direction to find out what '
, the back tick, ,
, and @
mean in CL?
Edit: Also, why am I supposed to return a list when I am trying to return a JSON object? I'm trying to understand this a bit better.
That was actually a super helpful answer. I was trying to figure out how CL returns specific types, but I couldn't really understand it at a first glance.
There is no JSON object, you probably want to return a JSON response. A response in woo is a normal list consisting of three items: the first item is the response code, the second is an alist that represent the headers and the optional third and final item is the response body.
You can learn more about the quote macro, backtick, comma and at operator in the practical Common Lisp book, especially this chapter explains the quote macro ('
) and this chapter explains the others.
Edit: The quote and backtick are probably better explained in this chapter.
@libre-man I cannot thank you enough for your insight on this. Thank you. I'll give them both a read. Going back to the original question, it makes perfect sense that a Woo response is a list with 3 items. Making the changes you had suggested above returns now the following:
woo: Unhandled FAST-HTTP.ERROR:CB-MESSAGE-COMPLETE in thread #<SB-THREAD:THREAD
woo: "main thread" RUNNING
woo: {1002D7FEA3}>:
woo: Callback Error: the message-complete callback failed
woo: "{\"MESSAGE\":\"Hello, World!\"}" fell through ETYPECASE expression.
woo: Wanted one of (NULL PATHNAME LIST (VECTOR (UNSIGNED-BYTE 8))).
Is this because MESSAGE
is returned instead of message
?
Sorry I made a mistake in the snippet. The third argument should be a list of strings, so (list 200 '(:content-type "application/json" :server "Woo") (list (jonathan:to-json '(:message "Hello, World!"))))
should work.
You could rewrite to this with ` to make to code look a bit nicer.
You would be correct. Thank you for all your help. I am curious how the backtick will make it cleaner, so I'll take a deep dive into the syntax of the language. I appreciate the great explanations
I do not have a lot of experience with Common Lisp, but I would like to learn it a bit better. I am having trouble with
:content-type "application/json"
. This is running with Docker, using Roswell. Here is the stack trace:Source