#language #cli #api-client #json-selector

gluescript

A blazingly fast HTTP client with a magnificent request building syntax, made for humans

2 releases

0.1.0 Oct 8, 2022

#164 in HTTP client

Download history 11/week @ 2023-11-10 16/week @ 2023-11-17 22/week @ 2023-11-24 15/week @ 2023-12-01 9/week @ 2023-12-08 15/week @ 2023-12-15 17/week @ 2023-12-22 7/week @ 2023-12-29 12/week @ 2024-01-05 11/week @ 2024-01-12 9/week @ 2024-01-19 12/week @ 2024-01-26 10/week @ 2024-02-02 18/week @ 2024-02-09 46/week @ 2024-02-16 77/week @ 2024-02-23

151 downloads per month
Used in 3 crates

Custom license

21KB
394 lines

🔗 glue

GitHub license PRs Welcome

Make requests, select JSON responses, nest them in other requests: A magnificent syntax for blazingly fast cli HTTP calls, made for humans.

Table of Contents

Getting started

Install & Update

At the moment, you can install or update glue for your system by building it from source. It has been done quite easy by the script install.sh.

All build dependencies (including Rust) will be deleted right after the installation automatically if Rust wasn't already on your system.

  1. Clone the repo
git clone https://github.com/mikesposito/glue
  1. Go to glue root directory
cd glue
  1. Add execute permission and run install.sh
chmod +x ./install.sh && ./install.sh

Usage

To start an interactive glue shell, simply run:

glue

alternatively, you can also execute a request directly:

glue <REQUEST>

The simplest request you can do with glue is using just the method and the url:

glue 'get https://dog.ceo/api/breeds/list/all'
# or in glue shell:
get https://dog.ceo/api/breeds/list/all

Syntax

Overview

The main gluescipt request syntax is the following:

[METHOD] [URL] [OPERATORS]

Methods available

Glue Keyword Description
get Executes a GET http call
post Executes a POST http call
patch Executes a PATCH http call
put Executes a PUT http call
delete Executes a DELETE http call
req Reuses a saved request response from memory

Operators available

Operators allow to execute operations on requests (body, headers params, nesting), on responses (selectors, variables)

Operation Syntax Example
JSON Result Selector ^selector ^$.message
Body attribute ~key=value ~username=admin
Body attribute quoted ~key="value" ~fullname="John Doe"
Raw JSON body ~#-json-# ~#-{"username": "admin"}-#
Header attribute *key=value *authorization=xxx
Header attribute quoted *key="value" *authorization="Bearer xxx"
Nested request { nested_request } get api.com/users/{get api.com/me}
Save response in var >var >login_request
Sequential request separator request**;** other_request req test1; req test2

JSON result selector

If the response is of type JSON, you can add a jsonpath selector to the request with the char ^. Glue will only return the desired value from the response. This applies also for Nested requests.

get https://dog.ceo/api/breeds/list/all^$.message.terrier

# OUTPUT:
# > [GET] https://dog.ceo/api/breeds/list/all
# 
# 
# [
#   [
#     "american",
#     "australian",
#     "bedlington",
#     "border",
#     "cairn",
#     "dandie",
#     "fox",
#     "irish",
#     "kerryblue",
#     "lakeland",
#     "norfolk",
#     "norwich",
#     "patterdale",
#     "russell",
#     "scottish",
#     "sealyham",
#     "silky",
#     "tibetan",
#     "toy",
#     "welsh",
#     "westhighland",
#     "wheaten",
#     "yorkshire"
#   ]
# ]

Body attributes

You can use the char ~ to add body attributes to the request:

post https://example.com/user/add ~username=admin
# or
post https://example.com/user/add~username=admin

# glue will send a body of type JSON 
# with a key "username" with value "admin"

Raw JSON Body

Raw JSON values can also be used between ~#-JSON- instead of single attributes:

post https://example.com/users ~#-{ "name": "John" }-#
# or 
post https://example.com/users~#-{ "name": "John" }-#

Note

Body attributes can take their value from another request's response by using nested requests feature.

Headers

You can use the char * to set headers to the request:

post https://example.com/user/add*authorization=6a75d4d7-84c3
# or
post https://example.com/user/add *authorization=6a75d4d7-84c3

# glue will set Authorization header
# to value "6a75d4d7-84c3"

Quotes can also be use to escape special glue chars or spaces in attributes:

post https://example.com/user/add*authorization="Bearer 6a75d4d7-84c3"

Note

Headers can take their value from another request's response by using nested requests feature.

Nested requests

One of the most useful features of glue is the request nesting.

You can reuse response values (total or partial) from a request to build another request.

Glue supports infinite nesting and will build a dependency tree, divide it in layers and execute each layer on parallel for the maximum time optimization.

You can use request nesting delimiting the desired nested request with {}:

get api.com/users/{ get api.com/me^$.user.id }/

# glue will execute this two requests:

# 1. api.com/me - and will select user.id from the response (eg. 12345)

# 2. api.com/users/12345/

Request can also be nested inside body or headers parameters:

get api.com/me *authorization={get api.com/login^$.access_token}/

Run file

You can also create a file with request to run, and pass the file path to glue with flag -f to execute it. You can try with one of the sample requests in examples folder:

glue -f examples/sample-request.glue

Multiple requests

Files can also contain multiple sequential requests separated by ;. Take a look at ./examples/sequential-requests.glue.

Save response in variable

You can save a request response in a temporary variable with a name of your choice with the char >, to reuse it without executing the call again.

get https://dog.ceo/api/breeds/list/all >test_req

to use the saved response:

req test_req

You can also use a selector on the saved response with ^:

req test_req^$.message.terrier

Note: Variables are available only in the same glueshell session and dropped at the end of it.

Contributing

The main purpose of this repository is to continue evolving glue core, making it faster and easier to use. Development of glue happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and improvements. Read below to learn how you can take part in improving glue.

Code of Conduct

glue has adopted a Code of Conduct that we expect project participants to adhere to. Please read the full text so that you can understand what actions will and will not be tolerated.

Contributing Guide

Read our contributing guide to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to glue.

Good First Issues

To help you get your feet wet and get you familiar with our contribution process, we have a list of good first issues that contain bugs which have a relatively limited scope. This is a great place to get started.

License

glue is MIT licensed.

Dependencies

~6–20MB
~291K SLoC