πŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more β†’
Socket
Sign inDemoInstall
Socket

getzy

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

getzy

A tiny yet capable HTTP/HTTPS client for Node.js. Native. Promise-based. Pluggable.

1.0.1
latest
Source
npm
Version published
Weekly downloads
2
-60%
Maintainers
0
Weekly downloads
Β 
Created
Source

Getzy

A tiny yet capable HTTP/HTTPS client for Node.js.
Native. Promise-based. Pluggable.

πŸ“š Table of Contents

  • Features
  • Installation
  • Usage
  • Request Options
  • Constructor & Configuration
  • Middleware & Integrations
  • API
  • Error Handling
  • Related
  • Contributing
  • License

✨ Features

  • Native only – Built using only Node.js's native http/https modules.
  • Promise-based – Clean async/await interface.
  • Retries – Automatic exponential backoff with jitter for retries.
  • Redirects – Follows redirects (default up to 3; configurable).
  • Middleware Support – Chain asynchronous plugins for logging, caching, authentication, etc.
  • Pluggable Integrations – Easily compose reusable integration logic.
  • CLI Support – Use getzy from the terminal for quick HTTP requests.

πŸš€ Installation

As a Library

Install via npm:

npm install getzy

As a CLI

Install globally:

npm install -g getzy

Or clone the repo and link it locally:

git clone https://github.com/Sectly/getzy.git
cd getzy
npm install
npm link

Now you can use getzy directly in your terminal.

πŸ›  Usage

As a Library

Create a client instance and make requests:

const Getzy = require('getzy');
const client = new Getzy();

// Optional: register an integration with before and after middleware
client.useIntegration({
  before: async ({ ctx }) => {
    console.log(`[β†’] ${ctx.method} ${ctx.url}`);
    return { ctx };
  },
  after: async ({ ctx, result }) => {
    console.log(`[βœ“] ${result.statusCode} ${result.statusText}`);
    return { ctx, result };
  }
});

(async () => {
  try {
    const res = await client.get('https://jsonplaceholder.typicode.com/posts/1');
    console.log(res.statusCode); // e.g., 200
    console.log(res.body.title); // Post title (if JSON response)
  } catch (err) {
    console.error('Request failed:', err);
  }
})();

CLI Usage

Getzy CLI enables you to perform HTTP requests directly from the terminal.

Basic Examples

  • Standard GET with JSON response:

    getzy get https://jsonplaceholder.typicode.com/posts/1 --json --pretty
    
  • GET without specifying method (defaults to GET):

    getzy https://jsonplaceholder.typicode.com/posts/1 --json
    
  • POST with JSON body provided via argument:

    getzy post https://api.example.com -H Content-Type:application/json -d '{"hello":"world"}'
    
  • Using piped input for the request body:

    cat body.json | getzy post https://api.example.com -p userId=5 -s
    
  • Chaining output with a tool like jq:

    getzy get https://jsonplaceholder.typicode.com/posts/1 --json | jq .
    

CLI Options

  • -X, -x <method>
    Set the HTTP method (GET, POST, etc). Overrides the default (GET).

  • -H, --headers k:v
    Add custom headers. Can be repeated for multiple headers.

  • -p, --params k=v
    Add query parameters. Can be repeated for multiple parameters.

  • -d, --body <json>
    Provide raw JSON or string as the request body.

    Note: If the request body is piped via stdin and is valid JSON, it will be parsed; otherwise, raw text is used.

  • -T, --timeout <ms>
    Set the request timeout in milliseconds.

  • -r, --retries <n>
    Set the maximum number of retry attempts.

  • -R, --redirects <n>
    Set the maximum number of redirects to follow (use 0 to disable).

  • --json
    Automatically add Accept: application/json header.

  • --pretty
    Prettify JSON output.

  • -s, --silent
    Output only the response body (suppress status and headers).

  • -v, --version
    Display the CLI version.

  • -h, --help
    Display the help message.

Piping is supported:

  • Input: Pipe request body via stdin.
  • Output: Response body is printed to stdout while logs/status info goes to stderr.

πŸͺ› Request Options

Each request method accepts an optional options object:

{
  headers: {},         // Custom headers (merged with default headers)
  body: {},            // Request body (JSON or string). **Streaming is not supported.**
  timeout: 10000,      // Timeout in ms
  redirects: 3,        // Maximum redirects (0 disables redirects)
  retries: 0,          // Maximum retry attempts
  baseRetryDelay: 500, // Initial delay for exponential backoff (ms)
  maxRetryDelay: 2000, // Maximum delay between retries (ms)
  params: {}           // Query parameters to append to URL
}

Note: When a request body is provided as an object, it is JSON-stringified automatically.
Also, if no Content-Type header is set and the body is an object, the client sets Content-Type to application/json.

πŸ”§ Constructor & Configuration

When instantiating Getzy, you can provide a configuration object to set defaults for all requests:

const client = new Getzy({
  defaultHeaders: { 'Accept': 'application/json' },
  defaultMaxRedirects: 3,
  defaultMaxRetryDelay: 2000,
  defaultTimeout: 10000,
  defaultRetries: 0,
  defaultBaseRetryDelay: 500,
});

The configuration parameters include:

  • defaultHeaders: Default HTTP headers for every request.
  • defaultMaxRedirects: Maximum number of redirects to follow.
  • defaultMaxRetryDelay: Maximum delay between retry attempts.
  • defaultTimeout: Request timeout in milliseconds.
  • defaultRetries: Number of retry attempts.
  • defaultBaseRetryDelay: Initial delay before retrying a request.

πŸ”Œ Middleware & Integrations

Getzy supports middleware in two phases:

  • Before Middleware:
    Modify the request context (e.g., add headers, log request details).
    If a middleware returns a result, the remaining request is skipped and the result is passed to the after phase.

  • After Middleware:
    Process the response (e.g., logging, error handling) before returning it to the caller.

Register middleware using:

// Single middleware function for a specific phase:
client.use(async ({ ctx }) => {
  ctx.options.headers = {
    ...ctx.options.headers,
    Authorization: 'Bearer your-token',
  };
  return { ctx };
}, 'before');

// As an integration (plugin) with both phases:
client.useIntegration({
  before: async ({ ctx }) => { /* ... */ return { ctx }; },
  after: async ({ ctx, result }) => { /* ... */ return { ctx, result }; }
});

Additionally, you can register a global middleware error handler:

client.onMiddlewareError((err, ctx, phase) => {
  console.error(`Middleware error in ${phase} phase:`, err);
});

πŸ“¦ API

Request Methods

client.get(url, options?)
client.post(url, options?)
client.put(url, options?)
client.delete(url, options?)
client.head(url, options?)
client.patch(url, options?)
client.options(url, options?)

Middleware

// Register a middleware for a phase ('before' or 'after')
client.use(fn, phase);

// Register an integration (object with before and/or after functions)
client.useIntegration({ before, after });

// Register a global middleware error handler
client.onMiddlewareError((err, ctx, phase) => { ... });

🚨 Error Handling

  • If a request fails (e.g., non-2xx response, network error, timeout), the returned error object will include:
    • error.response: The response object (if available) containing status, headers, body, etc.
    • error.request: Details of the attempted request.
  • Middleware errors are propagated via the global error handler (if registered) and will abort the request.

Here’s how Getzy compares to other popular HTTP clients:

Feature / ClientGetzyAxiosGotFetch (Node)tiny-json-http
Native Modules Onlyβœ…βŒβŒβœ…βœ…
Promise Supportβœ…βœ…βœ…βœ…βœ…
Retries (w/ backoff)βœ…βŒβœ…βŒβŒ
Redirect Supportβœ…βœ…βœ…βœ…βœ…
Middleware Supportβœ…βš οΈβœ…βŒβŒ
Plugin Systemβœ…βŒβœ…βŒβŒ
Streaming SupportβŒβœ…βœ…βœ…βŒ
Cookie Managementβš οΈβœ…βœ…βŒβŒ
Browser CompatibleβŒβœ…βŒβœ…βœ…
Lightweightβœ…βŒβš οΈβœ…βœ…

Legend: βœ… Supportedβ€ƒβŒ Not supportedβ€ƒβš οΈ Partial support or requires additional workarounds

🀝 Contributing

Contributions, ideas, and feedback are welcome!
Feel free to open an issue or pull request on GitHub.

πŸ“„ License

BSD 3-Clause License
Β© 2025 Sectly

Keywords

http

FAQs

Package last updated on 11 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts