2023-06-07 15:32:23 +02:00
# PostWoman
2024-10-19 22:40:15 +02:00
[![Actions Status ](https://github.com/alemidev/postwoman/actions/workflows/test.yml/badge.svg )](https://github.com/alemidev/postwoman/actions)
[![Crates.io Version ](https://img.shields.io/crates/v/postwoman )](https://crates.io/crates/postwoman)
[![Crates.io Downloads (latest version) ](https://img.shields.io/crates/dv/postwoman )](https://crates.io/crates/postwoman)
[![GitHub last commit ](https://img.shields.io/github/last-commit/alemidev/postwoman )](https://github.com/alemidev/postwoman/commits/dev/)
[![GitHub Issues or Pull Requests ](https://img.shields.io/github/issues/alemidev/postwoman )](https://github.com/alemidev/postwoman/issues)
2024-10-19 03:28:16 +02:00
A CLI api tester and request builder, totally not born out of frustration from some other tool...
2023-06-08 12:06:40 +02:00
## Why
2024-10-19 03:28:16 +02:00
I'd much rather edit my test routes in my text editor as bare config files and fire them via a CLI than fumble around some GUI application.
2023-06-21 23:19:52 +02:00
2024-10-19 22:22:12 +02:00
As an example, most API test tools have features to automatically split down query arguments from a built url. PostWoman doesn't bother, as your editor will most likely offer multi-cursors and search/replace to easily split off query parameters.
While PostWoman will never be as fully featured as other graphical tools, it doesn't need to be to provide a solid API testing framework.
2023-06-21 23:19:52 +02:00
# Usage
2024-10-19 22:40:15 +02:00
Install with `cargo install postwoman`
2024-10-19 03:28:16 +02:00
`postwoman` expects a `postwoman.toml` collection in your cwd. A different file or path can be specified with the global `-c` option.
2023-06-21 23:19:52 +02:00
2024-10-19 03:28:16 +02:00
Use `postwoman run <filter>` to send requests to all routes in current config matching given filter (regex). Use `.` as filter to run all.
2023-06-21 23:19:52 +02:00
2024-10-19 03:28:16 +02:00
## Examples
A collection can be super simple
2023-06-21 23:19:52 +02:00
2024-10-19 03:28:16 +02:00
```toml
[route.test]
url = "https://api.alemi.dev/debug"
2023-06-21 23:19:52 +02:00
```
2024-10-20 05:19:35 +02:00
But more complex options are available, check out provided `postwoman.toml` for some (ready to run!) examples.
2024-10-19 22:22:12 +02:00
2024-10-20 05:19:35 +02:00
More complex collection trees can be achieved with `include` top level field.
Includes are idempotent and always resolved relative from parent collection's directory.
2024-10-19 22:22:12 +02:00
2024-10-20 05:19:35 +02:00
```toml
include = [
"other.toml",
"even/more.toml"
2024-10-19 22:22:12 +02:00
]
```
### Running
Show collection summary
```
$ postwoman
2024-10-20 05:19:35 +02:00
~@ postwoman/0.3.1
-> postwoman.toml
+ PW_TOKEN=set-me-as-and-environment-variable!
- healthcheck GET https://api.alemi.dev/
- debug PUT https://api.alemi.dev/debug
- benchmark GET https://api.alemi.dev/look/into/the/void
- notfound GET https://api.alemi.dev/not-found
- payload POST https://api.alemi.dev/debug
- cookie GET https://api.alemi.dev/getcookie
2024-10-19 22:22:12 +02:00
```
Run all endpoints matching `.` (aka all of them)
```
$ postwoman run .
2024-10-20 05:19:35 +02:00
~@ postwoman/0.3.1
: [05:14:47.241122] postwoman.toml::healthcheck sending request...
+ [05:14:47.411708] postwoman.toml::healthcheck done in 170ms
2024-10-19 22:28:16 +02:00
{
2024-10-19 22:22:12 +02:00
"example": [
"https://api.alemi.dev/debug",
"https://api.alemi.dev/msg",
"https://api.alemi.dev/mumble/ping"
],
2024-10-20 05:19:35 +02:00
"time": "Sunday, 20-Oct-2024 03:14:47 GMT",
2024-10-19 22:22:12 +02:00
"up": true
}
2024-10-20 05:19:35 +02:00
: [05:14:47.411807] postwoman.toml::debug sending request...
+ [05:14:47.574391] postwoman.toml::debug done in 162ms
2024-10-19 22:22:12 +02:00
/debug?body=json& cache=0
2024-10-20 05:19:35 +02:00
: [05:14:47.574474] postwoman.toml::benchmark sending request...
+ [05:14:47.726527] postwoman.toml::benchmark done in 152ms
: [05:14:47.726605] postwoman.toml::notfound sending request...
+ [05:14:47.878922] postwoman.toml::notfound done in 152ms
2024-10-19 22:22:12 +02:00
nginx/1.26.2
2024-10-20 05:19:35 +02:00
: [05:14:47.879000] postwoman.toml::payload sending request...
+ [05:14:48.039053] postwoman.toml::payload done in 160ms
2024-10-19 22:22:12 +02:00
{
"body": "{\n\t\"complex\": {\n\t\t\"json\": \"payloads\",\n\t\t\"can\": \"be\",\n\t\t\"expressed\": \"this\",\n\t\t\"way\": true\n\t}\n}",
"headers": {
"accept": [
"*/*"
],
"connection": "close",
"content-length": "94",
2024-10-20 05:19:35 +02:00
"user-agent": "postwoman@sample/0.3.1",
2024-10-19 22:22:12 +02:00
"x-forwarded-proto": "https",
"x-real-ip": "93.34.149.115",
2024-10-20 05:19:35 +02:00
"x-real-port": 46945,
"x-user-agent": "postwoman@sample/0.3.1"
2024-10-19 22:22:12 +02:00
},
"method": "POST",
"path": "/debug",
2024-10-20 05:19:35 +02:00
"time": 1729394088.0156112,
2024-10-19 22:22:12 +02:00
"version": "HTTP/1.0"
}
2024-10-20 05:19:35 +02:00
: [05:14:48.039099] postwoman.toml::cookie sending request...
+ [05:14:48.168725] postwoman.toml::cookie done in 129ms
2024-10-19 22:22:12 +02:00
SGF2ZSBhIENvb2tpZSE=
2023-06-21 23:19:52 +02:00
```
2024-10-19 22:28:16 +02:00
Debug a specific route passing `--debug` :
```
$ postwoman run notfound --debug
2024-10-20 05:19:35 +02:00
~@ postwoman/0.3.1
: [05:15:16.960147] postwoman.toml::notfound sending request...
+ [05:15:17.120647] postwoman.toml::notfound done in 160ms
2024-10-19 22:28:16 +02:00
Response {
url: "https://api.alemi.dev/not-found",
status: 404,
headers: {
"server": "nginx/1.26.2",
2024-10-20 05:19:35 +02:00
"date": "Sun, 20 Oct 2024 03:15:17 GMT",
2024-10-19 22:28:16 +02:00
"content-type": "text/html",
"content-length": "153",
"connection": "keep-alive",
"vary": "Accept-Encoding",
},
}
Body: < html >
< head > < title > 404 Not Found< / title > < / head >
< body >
< center > < h1 > 404 Not Found< / h1 > < / center >
< hr > < center > nginx/1.26.2< / center >
< / body >
< / html >
```