Socket
Socket
Sign inDemoInstall

javascript-request-manager

Package Overview
Dependencies
5
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    javascript-request-manager

Request Manager for JavaScript | Handle your requests easily


Version published
Weekly downloads
0
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Javascript Request Manager (with Axios)

Installation

Install with npm

npm install --save javascript-request-manager

Install with yarn

yarn add javascript-request-manager

ES6 Usage Example (it will be updated as soon as possible.)


// Requests file : Create it once for always use :)
// **Requests.js**
const BASE_URL = "https://taluttasgiran.com.tr/api/v2/"
const Methods = {
    POST: "POST",
    GET: "GET",
    PUT: "PUT",
    DELETE: "DELETE"
}
const RequestRoutes = {
    MOBILE_LOGIN: "Mobile/Auth",
    MOBILE_POSTS: "Mobile/Posts",
}
const Requests = {
    MOBILE_LOGIN: {
       route: RequestRoutes.MOBILE_LOGIN,
       method: Methods.POST,
       showRefreshComponent: true, // not required // this for ReactJS component :)
       isTokenRequired: true, // not required
       headers: { "Content-Type": "application/json" } // not required
    }
}
// USAGE
import RequestManager from 'javascript-request-manager'
import {BASE_URL, Requests} from './Requests'

const RManager = new RequestManager(RequestErrors, RequestErrorMessages);
const token = "abcdefghi14334dfsdfsdf3243esd"
RManager
    .baseURL(BASE_URL)
    .setToken(token)
    .body({email:"info@taluttasgiran.com.tr",password:"123456"}) // post body or get params
    .builder(Requests.MOBILE_LOGIN)
    .onSuccess((res)=>{
        console.log(res)
    })
    .onFail((err)=>{
        console.log(err.message)
    })
    .makeRequest();
// RequestErrors and RequestErrorMessages
export const RequestErrorMessages = {
  SYSTEM_ERROR: "Sistemlerde bir sorun oluştu daha sonra tekrar deneyiniz.",
  UNAUTHORIZED: "Yetkisiz giriş",
  SERVER_ERROR: "Sunucularda bir sorun oluştu. Lütfen daha sonra tekrar deneyiniz"
};
export const RequestErrors = {
  UNHANDLED_ERROR: {
    statusDescription: "Unhandled Error",
    message: RequestErrorMessages.SYSTEM_ERROR,
    showRefreshComponent: false,
  },
  UNAUTHORIZED: {
    statusCode: 401,
    statusDescription: "Unauthorized",
    message: RequestErrorMessages.UNAUTHORIZED,
    showRefreshComponent: false,
  },
  FORBIDDEN: {
    statusCode: 403,
    statusDescription: "Forbidden",
    message: RequestErrorMessages.UNAUTHORIZED,
    showRefreshComponent: false,
  },
  NOT_FOUND: {
    statusCode: 404,
    statusDescription: "Not Found",
    message: RequestErrorMessages.SYSTEM_ERROR,
    showRefreshComponent: true,
  },
  METHOD_NOT_ALLOWED: {
    statusCode: 405,
    statusDescription: "Method Not Allowed",
    message: RequestErrorMessages.SYSTEM_ERROR,
    showRefreshComponent: true,
  },
  INTERNAL_SERVER_ERROR: {
    statusCode: 500,
    statusDescription: "Internal Server Error",
    message: RequestErrorMessages.SERVER_ERROR,
    showRefreshComponent: true,
  },
  BAD_GATEWAY: {
    statusCode: 502,
    statusDescription: "Bad Gateway",
    message: RequestErrorMessages.SERVER_ERROR,
    showRefreshComponent: true,
  },
  SERVICE_UNAVAILABLE: {
    statusCode: 503,
    statusDescription: "Service Unavailable",
    message: RequestErrorMessages.SERVER_ERROR,
    showRefreshComponent: true,
  },
  GATEWAY_TIMEOUT: {
    statusCode: 504,
    statusDescription: "Gateway Timeout",
    message: RequestErrorMessages.SERVER_ERROR,
    showRefreshComponent: true,
  },
};

Keywords

FAQs

Last updated on 20 Sep 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc