Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fdy-scraping

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fdy-scraping

`fdy-scraping` is a versatile HTTP client designed for making API requests with support for proxy configuration, debugging, and detailed error handling. It utilizes the [`got-scraping`](https://github.com/apify/got-scraping) library for HTTP operations.

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
124
decreased by-82.13%
Maintainers
0
Weekly downloads
 
Created
Source

fdy-scraping

fdy-scraping is a versatile HTTP client designed for making API requests with support for proxy configuration, debugging, and detailed error handling. It utilizes the got-scraping library for HTTP operations.

Installation

To use fdy-scraping, you need to install the got-scraping library. Run the following command to install it via npm:

npm install fdy-scraping

Usage

Importing the Client

Import fdy-scraping into your Node.js application:

const fdy = require("fdy-scraping");

OR

import fdy from "fdy-scraping";

Creating a Client Instance

Create a new client instance with custom options:

create(options?: FetchClientOptions, debug?: boolean): FdyFetchClient;
const client = fdy.create(
  {
    headers: { Authorization: "Bearer your-token" },
    proxy: {
      ip: "127.0.0.1",
      port: 8080,
      protocol: "http",
      username: "username",
      password: "password",
    },
    baseUrl: "https://api.example.com",
  },
  true
); // Set debug mode to true

Making HTTP Requests

You can use the client to make various types of HTTP requests:

Request
request(url, method, body = undefined, headers = undefined, options = undefined)
client
  .request("/endpoint", "POST", undefined, { Accept: "application/json" })
  .then((response) => {
    console.log(response.data); // Response data
  })
  .catch((error) => {
    console.error("Error:", error.message);
  });
GET Request
get(url, headers = {}, options = {}, enableDebug = false)
client
  .get("/endpoint", { Accept: "application/json" })
  .then((response) => {
    console.log(response.data); // Response data
  })
  .catch((error) => {
    console.error("Error:", error.message);
  });
POST Request
post(url, body = undefined, headers = {}, options = {}, enableDebug = false)
client
  .post("/endpoint", JSON.stringify({ key: "value" }), {
    "Content-Type": "application/json",
  })
  .then((response) => {
    console.log(response.data); // Response data
  })
  .catch((error) => {
    console.error("Error:", error.message);
  });
PUT Request
put(url, body = undefined, headers = {}, options = {}, enableDebug = false)
client
  .put("/endpoint", JSON.stringify({ key: "new-value" }), {
    "Content-Type": "application/json",
  })
  .then((response) => {
    console.log(response.data); // Response data
  })
  .catch((error) => {
    console.error("Error:", error.message);
  });
DELETE Request
delete(url, headers = {}, options = {}, enableDebug = false)
client
  .delete("/endpoint", { Accept: "application/json" })
  .then((response) => {
    console.log(response.data); // Response data
  })
  .catch((error) => {
    console.error("Error:", error.message);
  });

Error Handling

fdy-scraping provides detailed error information through the FdyFetchClientError class. Errors include the status code, response data, and request configuration.

client.get("/invalid-endpoint").catch((error) => {
  if (error instanceof fdy.FdyFetchClientError) {
    console.error("Custom Error Details:");
    console.error("Status:", error.status);
    console.error("Response:", error.response);
    console.error("Config:", error.config);
  } else {
    console.error("General Error:", error.message);
  }
});

Configuration Options

FetchClientOptions

  • headers: Optional object containing default headers for requests.
  • proxy: Optional object for proxy configuration.
    • ip: IP address of the proxy server.
    • port: Port of the proxy server.
    • protocol: Protocol used by the proxy (http or https).
    • username: Optional username for proxy authentication.
    • password: Optional password for proxy authentication.
  • baseUrl: Optional base URL for requests.

Debug Mode

Debug mode can be enabled by passing true as the second argument to FdyFetchClient.create. When enabled, additional error information will be logged to the console.

License

This project is licensed under the MIT License - see the LICENSE file for details.


Feel free to adjust the paths, options, or methods according to your actual implementation and package setup.

Keywords

FAQs

Package last updated on 21 Sep 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc