* Fixed compilation from commandline

* Added readme
This commit is contained in:
Andreas Schneider 2015-09-18 11:12:22 +02:00
parent f1cf1e16b6
commit 22605a453e
2 changed files with 103 additions and 0 deletions

101
README.md Normal file
View File

@ -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 <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.
This can be repeated multiple times.
`Header <http header>`
: Sets the given http header for the request.
This can be repeated multiple times.
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`
`Method <HTTP Method>`
: This sets the method to be used for the call.
`Call <URL>`
: 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.
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`.

View File

@ -19,6 +19,8 @@
program restemplate; program restemplate;
{$mode objfpc}
{.$define use_synapse} {.$define use_synapse}
{$define use_fclweb} {$define use_fclweb}