restemplate is a simple tool I wrote, to simplify queries against REST services.
Usually I used curl together with a lot of text files containing the requests I send and manually replaced the necessary content within the URL and the payload.
* Simple templates/profiles specifying how a call looks like
* Variable replacement in Headers, URIs and the Payload
* Query users for variables
* Store "last" variable values to be easily reused
* SSL support via openssl
- dynamically loads openssl, so if you don't use it, you don't need it
* Entirely written in FreePascal
- ... it is therefore cross-platform (compilable :-))
## Usage
Calling restemplate is as easy as calling `restemplate <profile or file>`.
The first (and only) parameter is either a valid filename or the name of a profile (more on that later).
Without any parameters, it lists the known profiles.
## Example
Let's start with a simple example, and explain the seen features later.
```
Ask username
Ask key
Ask value
Header X-UserName: @username
Method POST
Call http://localhost/myservice/keys/@key
{
"value": "@value"
}
```
Executing this profile will result in:
```
$ restemplate example.rest
username: myuser
key: somekey
value: foobar
Calling http://localhost/myservice/keys/somekey
Status: 200 (OK)
Headers:
Content-Type: application/json
{"statusCode": 0}
```
## Fileformat
The profiles are simple text files, parsed line by line.
The parser starts in command mode. Each line has to start with a valid command.
Empty lines or lines starting with "#" are ignored (which can be used to make profiles more readable and comment out commands without deleting them).
Once the first none-empty line is unrecognized (no command found), the parser will treat the remaining part of the profile as payload to be sent within the request.
### Commands
`Ask <variablename>`
: Prompts the user for the input of `<variablename>`. If the value has been given in a previous run, it is suggested as default value so the user can simply accept the "last" value. This eases re-runs of the same profile with only minor (or no) changes.
: Prompts the user for the hidden input of `<variablename>`. This can be used to input passwords. These values are not persisted and therefore no default values are suggested.
Variables in the form of `@<variablename>` are replaced accordingly.
`BasicAuth <username> <password>`
: Sets the necessary header for basic authentication. The first char after `BasicAuth` (usually a space) is treated as separator for `<username>` and `<password>`. So in case the username itself contains a space, you can safely use a different char here. Example: `BasicAuth#Complicated Username With Spaces#andsomepassword`
: This prepares the actual call by providing the URL to be called.
Variables in the form of `@<variablename>` are replaced accordingly.
## Profiles
Having a profile in a local file can be inconvenient if you have restemplate in the `$PATH` for example and want to call it from "anywhere".
Therefore you can save profiles in `~/.config/restemplate/templates/*.rest`. The filename of these files (sans `.rest`) will be used as profile name and listed as well as recognized by restemplate.
## Compiling
You need at least FreePascal 3.0 and it is recommended to use Lazarus as IDE.