Nice little macro you have here. I've had to use it for a swagger spec, and it worked pretty well. Except I needed some stuff in there as well. So I decided to add these & also fix some of the FIXME comments.
Apply whatever you want from it.
Fixes
Pseudo-dynamic request content type instead of the hardcoded application/json-string
Deprecated warning for eval-when
The JSON assumption & body response mapping
Drakma has a builtin variable *text-content-types* which says what body content is definitely text. So since drakma automatically maps the response body to characters based on the content type header, I've added a let-binding after the generated URL which overrides the default drakma:*text-content-types* to ensure correct behavior for json decoding which comes after. So leaving the default behavior the same, while the assumed json body is dropped. The generated function now also returns the string/byte-array when the content type header is not json as its mime subtype.
base-path to endpoint
Idk if you noticed this, but the parameters for the generated functions were applied to the base-path, not to the endpoint, which seems erroneous? So I put that fix in a separate commit as well.
In my case at least I got an error, because the endpoints included the path variables, not the basepath...
Additions
default-headers keyword
The keyword allows to add in :additional-headers some default headers. The headers will be overwritten by headers when applicable. I needed to add some custom authentication headers, so I added this one.
Optional export keyword
Setting the keyword to t automatically adds an export statement for the function symbol. Defaults to nil, so it does not mess with the existing behavior. I wanted a separate package with exported function symbols, so I added this.
Hello,
Nice little macro you have here. I've had to use it for a swagger spec, and it worked pretty well. Except I needed some stuff in there as well. So I decided to add these & also fix some of the FIXME comments.
Apply whatever you want from it.
Fixes
application/json
-stringeval-when
The JSON assumption & body response mapping
Drakma has a builtin variable
*text-content-types*
which says what body content is definitely text. So since drakma automatically maps the response body to characters based on the content type header, I've added alet
-binding after the generated URL which overrides the defaultdrakma:*text-content-types*
to ensure correct behavior for json decoding which comes after. So leaving the default behavior the same, while the assumed json body is dropped. The generated function now also returns the string/byte-array when the content type header is not json as its mime subtype.base-path
toendpoint
Idk if you noticed this, but the parameters for the generated functions were applied to the
base-path
, not to theendpoint
, which seems erroneous? So I put that fix in a separate commit as well.In my case at least I got an error, because the endpoints included the path variables, not the basepath...
Additions
default-headers
keywordThe keyword allows to add in
:additional-headers
some default headers. The headers will be overwritten byheaders
when applicable. I needed to add some custom authentication headers, so I added this one.Optional
export
keywordSetting the keyword to
t
automatically adds anexport
statement for the function symbol. Defaults tonil
, so it does not mess with the existing behavior. I wanted a separate package with exported function symbols, so I added this.Thanks in advance for reviewing the PR.