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

@svkhrobbeck/fetcher

Package Overview
Dependencies
Maintainers
0
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@svkhrobbeck/fetcher

Fetcher — bu Axiosdan ilhomlangan to'liq xususiyatli HTTP kutubxonasi bo'lib, zamonaviy JavaScript muhitlarida HTTP so'rovlarini amalga oshirishni soddalashtiradi. Fetcher sizga qulay interfeys, so'rovlarni bekor qilish, interceptorlar, xatoliklarni boshq

  • 2.4.8
  • latest
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

Fetcher Library

Fetcher — bu Axiosdan ilhomlangan to'liq xususiyatli HTTP kutubxonasi bo'lib, zamonaviy JavaScript muhitlarida HTTP so'rovlarini amalga oshirishni soddalashtiradi. Fetcher sizga qulay interfeys, so'rovlarni bekor qilish, interceptorlar, xatoliklarni boshqarish va boshqa ko'plab imkoniyatlarni taqdim etadi.

Imkoniyatlar

  • So'rov va Javob Interceptorlari: Har bir so'rov yoki javobdan oldin yoki keyin maxsus logikalarni bajaring.
  • Bekor Qilish Qo'llab-quvvatlovi (Cancel Token): Istalgan paytda so'rovlarni bekor qilish va boshqarish.
  • So'rov va Javob Ma'lumotlarini Transformatsiya qilish: Ma'lumotlarni o'zgartirish uchun transformData funksiyasidan foydalaning.
  • Xatoliklarni Aniq Ko'rsatish (FetcherError): Xatoliklarni boshqarish uchun aniq va to'liq xatolik xabarlari.
  • Adapter Qo'llab-quvvatlovi: Har xil muhitlar (masalan, brauzer va Node.js) uchun mos adapterlar (fetch va xhr).
  • Kengaytiriladigan Konfiguratsiyalar: Standart va maxsus konfiguratsiyalarni birlashtirish.
  • Avtomatik URL Yaratish: Parametrlarni qulay tarzda qo'shib, URL yaratish.
  • Promisified API: Kutish (await) va Promise asosida ishlash.

O'rnatish

Fetcher kutubxonasini NPM orqali o'rnating:

npm install @svkhrobbeck/fetcher

Yoki Yarn orqali:

yarn add @svkhrobbeck/fetcher

Foydalanish Ko'rsatmalari

Oddiy GET So'rovi

import fetcher from "@svkhrobbeck/fetcher";

fetcher
  .get("https://api.example.com/data")
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.error("Error fetching data:", error);
  });

POST So'rovi bilan Ma'lumot Yuborish

fetcher
  .post("https://api.example.com/users", {
    name: "Ichigo Kurosaki",
    email: "ichigo.kurosaki@example.com"
  })
  .then(response => {
    console.log("User created:", response.data);
  })
  .catch(error => {
    console.error("Error creating user:", error);
  });

So'rovlarni Bekor Qilish

const { token, cancel } = fetcher.CancelToken.source();

fetcher
  .get("https://api.example.com/data", {
    cancelToken: token
  })
  .catch(error => {
    if (fetcher.isCancel(error)) {
      console.log("Request canceled:", error.message);
    } else {
      console.error("Error:", error);
    }
  });

// So'rovni istalgan vaqtda bekor qilish
cancel("Operation canceled by the user.");

Interceptorlardan Foydalanish

// So'rov Interceptori
fetcher.interceptors.request.use(
  config => {
    console.log("Request started:", config);
    return config;
  },
  error => {
    return Promise.reject(error);
  }
);

// Javob Interceptori
fetcher.interceptors.response.use(
  response => {
    console.log("Response received:", response);
    return response;
  },
  error => {
    return Promise.reject(error);
  }
);

So'rovlarni Yaratish

Fetcher bilan moslashtirilgan instansiyani yaratish va undan foydalanish:

const customFetcher = fetcher.create({
  baseURL: "https://api.example.com",
  headers: {
    Authorization: "Bearer YOUR_ACCESS_TOKEN"
  }
});

customFetcher
  .get("/protected-data")
  .then(response => console.log(response.data))
  .catch(error => console.error("Error fetching protected data:", error));

Imkoniyatlarning To'liq Ro'yxati

  • Interceptor Manager: So'rov va javob interceptorlarini boshqarish imkoniyati.
  • FetcherError: Xatoliklarni aniq va to'liq ko'rsatish uchun yangi sinf.
  • Cancel Token: So'rovlarni bekor qilish uchun kuchli mexanizm.
  • Transform Data: Ma'lumotlarni kerakli formatga o'zgartirish.
  • Adapter Qo'llab-quvvatlash: Fetch va XHR adapterlari.
  • Kengaytiriladigan Konfiguratsiyalar: Moslashuvchan va kengaytiriladigan konfiguratsiyalar.
  • Promisified API: await va Promise yordamida ishlashni soddalashtiradi.
  • Avtomatik URL Yaratish: Query parametrlar va URL yaratish uchun yordamchi funksiya.
  • Kengaytiriladigan Sozlamalar: Yangi instansiyalar yaratish va konfiguratsiyalarni boshqarish imkoniyati.

Kutubxona Yozuvchisi

  • Muallif: Suhrobbek Soatov
  • GitHub: svkhrobbeck

Keywords

FAQs

Package last updated on 12 Oct 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