From 22605a453e4ae1c861a9f33ba14acde210a05f2c Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Fri, 18 Sep 2015 11:12:22 +0200 Subject: [PATCH] * Fixed compilation from commandline * Added readme --- README.md | 101 ++++++++++++++++++++++++++++++++++++++++++++++++ restemplate.lpr | 2 + 2 files changed, 103 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..c4bf649 --- /dev/null +++ b/README.md @@ -0,0 +1,101 @@ +# restemplate + +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. + +To ease this, I wrote restlet. + +## Features + +* Supports all HTTP methods +* 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 `. + +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 ` +: Prompts the user for the input of ``. 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. + This can be repeated multiple times. + +`Header ` +: Sets the given http header for the request. + This can be repeated multiple times. + Variables in the form of `@` are replaced accordingly. + +`BasicAuth ` +: Sets the necessary header for basic authentication. The first char after `BasicAuth` (usually a space) is treated as separator for `` and ``. So in case the username itself contains a space, you can safely use a different char here. Example: `BasicAuth#Complicated Username With Spaces#andsomepassword` + +`Method ` +: This sets the method to be used for the call. + +`Call ` +: This prepares the actual call by providing the URL to be called. + Variables in the form of `@` 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. + +Compiling from commandline is as easy as: `fpc -XX -CX -Xs -Fujtemplate restemplate.lpr` + +If you use Lazarus, you can simply open the project file `restemplate.lpr`. \ No newline at end of file diff --git a/restemplate.lpr b/restemplate.lpr index 5f3e000..5bb65d7 100644 --- a/restemplate.lpr +++ b/restemplate.lpr @@ -19,6 +19,8 @@ program restemplate; +{$mode objfpc} + {.$define use_synapse} {$define use_fclweb}