restclient.el
restclient.el copied to clipboard
Get content from file for HTTP request body.
My text.rc file
:REQUEST_BODY = <<
{
"id": 1,
"name": "company Name"
}
# Update company's name
POST :API_TEST/updateCompany
:REQUEST_BODY
And it's HTTP request work fine. OK.
Question: Can I get content for variable REQUEST_BODY from file?
I want something like this:
:REQUEST_BODY = /path/to/file
Is it possible?
You can do something like this:
:token := (with-temp-buffer (insert-file-contents "token") (buffer-string))
Thanks. It's work. Here my example:
:REQ_BODY := (with-temp-buffer (insert-file-contents "d:/test/company/my.json") (buffer-string))
But has another problem. I want to extract folder path as another varable. And I want to concatenate folder path and file name.
Here snippet:
:DIR_PREFIX = "d:\\test\\company"
:REQ_BODY := (with-temp-buffer (insert-file-contents (concat ":DIR_PREFIX" "my.json")) (buffer-string))
But I get error:
Opening input file: Invalid argument, d:/test/company/:DIR_PREFIXmy.json
You can use something like this:
:ignore := (setq my-dir-prefix "/path/do/dir")
:DIR_PREFIX := my-dir-prefix
:REQ_BODY := (concat my-dir-prefix "my.json")
Thanks. Here work code:
:ignore := (setq dir-prefix-company "d:/tests/company/json")
:REQ_BODY := (with-temp-buffer (insert-file-contents (concat (file-name-as-directory dir-prefix-company) "my.json")) (buffer-string))
I don't know about :ignore. In description of package restclient I'm not found anything about :ignore. Where you found information about :ignore? Thank you!
:ignore is a randomly chosen name which is used to apply side effects. You can call it whatever you want.
I found in description what are you talking about:
There's no way to reference earlier declared restclient variables, but you can always use setq to save state
Now, I understand how it's work. Thank you!
if it's able to write some lisp code right after request code block to handle response content would be great.