npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rest-cli

v1.8.13

Published

A request runner inspired by [REST Client](https://github.com/Huachao/vscode-restclient).

Downloads

61

Readme

Rest CLI

A request runner inspired by REST Client.

This tool is intended to be compliant with Hauchao's VSCode plugin so that requests can be sequenced via command line tools.

There is no intention to extend features in this project beyond what is already capable in the plugin. Ideally, one can execute the very same files with the same environment interchangeably between the plugin and this tool.

If you need extra features, feel free to fork this project.

Usage

npm install -g rest-cli

# A single file, simple output.
# Shows stats, request method, and URL.
restcli myrequest.http

# A sequence of files.
restcli requests/*.http

# All .http files in the current directory.
restcli .

# Modify retry count (default: 3).
restcli --retry 5 myrequest.http

# A named request within a file.
restcli --pick myname myrequest.http

# Hide the stats (1: [2]).
restcli --no-stats myrequest.http

# Show different level of information.
restcli --show headers myrequest.http
restcli --show body myrequest.http
restcli --show full myrequest.http
restcli --show exchange myrequest.http

# Use production env variables.
restcli --env production myrequest.http

# Load in a json file of variables.
restcli --env env.json myrequest.http

# Disable colour.
restcli --no-color myrequest.http

API

This package exports a file parser and utilities for automating your requests.

See the main.ts file for extended usage.

Typescript defs are also exported.

Example

import { RestParser } from 'rest-cli';

(async () => {
    const parser = new RestParser();
    await parser.readFile("./myrequest.http");
    
    const request = await parser.get(0);
    console.log(request.toString());
    
    const { response } = await request.request();
    console.log(response.getBody());
})();

Node v8

This uses async iterators and therefore only supports Node v10. Note, as of January 2020, Node v8 is end-of-life and unsupported. If you really need Node v8, you can hack a solution with the --harmony_async_iterator flag.

Something like:

echo "#!/usr/bin/env node --harmony_async_iterator" > restcli
echo "require('rest-cli').main()" >> restcli
chmod +x restcli
./restcli

HTTP Language

This follows the standard RFC 2616, with templating as defined by vscode-restclient.

Example file

@baseUrl = https://example.com/api

# @name login
POST {{baseUrl}}/api/login HTTP/1.1
Content-Type: application/x-www-form-urlencoded

name=foo&password=bar

###

@authToken = {{login.response.headers.X-AuthToken}}

# @name createComment
POST {{baseUrl}}/comments HTTP/1.1
Authorization: {{authToken}}
Content-Type: application/json

{
    "content": "fake content"
}

###

@commentId = {{createComment.response.body.$.id}}

# @name getCreatedComment
GET {{baseUrl}}/comments/{{commentId}} HTTP/1.1
Authorization: {{authToken}}

###

# @name getReplies
GET {{baseUrl}}/comments/{{commentId}}/replies HTTP/1.1
Accept: application/xml

###

# @name getFirstReply
GET {{baseUrl}}/comments/{{commentId}}/replies/{{getReplies.response.body.//reply[1]/@id}}

Not supported

  • $aadToken
  • extension (%varname) environment variables

Supported Rest-Client settings

It's lies, only environmentVariables is currently supported.

Below are defaults.

{
  "rest-client.certificates": {},
  "rest-client.environmentVariables": {
    "$shared": {}
  },
  "rest-client.decodeEscapedUnicodeCharacters": false,
  "rest-client.defaultHeaders": {
    "User-Agent": "vscode-restclient"
  },
  "rest-client.excludeHostsForProxy": [],
  "rest-client.followredirect": true,
  "rest-client.formParamEncodingStrategy": "always",
  "rest-client.rememberCookiesForSubsequentRequests": true,
  "rest-client.timeoutinmilliseconds": 0,
}

TODO

There's a lot to do to complete this tool. Most of these are things that are missing to make it more compatible with the plugin.

Feel free to jump in on any of these.

  • just use yargs already
  • variables should be recursively interpolated when used - instead of statically
  • GraphQL support
  • multipart file loading support
  • cookies??
  • more doc comments
  • better readme docs
  • interpolating {{$shared name}} in environment files

Per-request settings:

  • escaped unicode
  • follow redirects
  • form param encoding
  • preview option (overrides CLI + settings)
  • remember cookies
  • timeout

Tests:

  • functions
  • request (fill, slug, body)
  • restfile
  • utils (basicAuth, bodyAsString, ServerError)
  • parser (out-of-order, iterator, get)

CLI options:

  • timeout
  • config file
  • disable confirm prompts
  • save to folder (optionally just files or everything)

Settings:

  • certificates
  • escaped unicode
  • default headers
  • follow redirects
  • form param encoding
  • preview option (overridden by CLI + per-request setting)
  • proxy exclude hosts
  • remember cookies
  • timeout