restclient.el icon indicating copy to clipboard operation
restclient.el copied to clipboard

Is it possible to define variales for different environments

Open ryang-bgl opened this issue 3 years ago • 1 comments

Hi,

Thanks a lot for authoring this awesome package.

Wonder if there is a way to switch between different environments for the vars in the restclient file. eg. I might use the same set of request (urls) for local and test environments. some vars like hostname will be different for different environments. Would be nice to easily switch environments. One solution would be to put environment related vars in a separate file and included them at the beginning of the restclient file.

What do you think?

Thanks

ryang-bgl avatar Nov 16 '21 04:11 ryang-bgl

I managed to achieve what I need using the following approach, document it here in case someone might find it useful.

  1. put variables in a separate file, like in local.el (setq api-host "http://localhost:9000" user-name "test-user")
  2. load the file at the begining of the restclient file:

(load (concat (file-name-directory buffer-file-name) "local.el"))

  1. evaluate the load statement
  2. then reference those variables in restclient file: :api-host := (concat api-host "/get-users") :custom-headers := << (concat "username: " user-name "\n" "userId: " 1 "\n")

You can have another file called production.el and just put the same set of variables. when you want to switch envs, just evaluate the loading statement of that env.

@pashky if you think the above is ok, could you help to put those into documentation?

Thanks

ryang-bgl avatar Nov 17 '21 04:11 ryang-bgl