Skip to content

baseservice is a class that contains all methods with or without auth. just create the instance and pass the data to the endpoint.

Notifications You must be signed in to change notification settings

CodeNation-Studio-Dev/codenation_lib_base_service

Repository files navigation

base-service

Made with create-react-library

NPM JavaScript Style Guide

Install

npm install --save base-service-fran-dev

Usage

The main purpose is to create a class ob the basic methods for the API requests. Create a service with your BASE_PATH and API endpoint and you will access to the following methods. All methods use Axios request.

-> postData(formdata) -> formdata is the data send to the API. -> postData has the POST method. -> headers : "Content-Type":"application/json" -> Url pass as parameter on the constructor of your class. (endpioint of api)

Create (service).js file

//Methods of BaseService

  async postData(formData){}
  async postDataAuth(formData, logout){}
  async editData(id, formData){}
  async editDataAuth(id, formData, logout){}
  async getAll(page, numberOfItems){}             //page & numberOfItems are optional defaults = ""
  async getAllAuth(logout, page, numberOfItems){} //page & numberOfItems are optional defaults = ""
  async getAllById(id){}          
  async getAllByIdAuth(id, logout){}
  async getById(id){}
  async deleteAuth(id, logout){}
  async delete(id, logout){}
  async filter(irequestFilter){} 
  // let irequestFilter = []
  // irequestFilter.push({'key':'X', 'value': '1'})
  // irequestFilter.push({'key':'y', 'value': '2'})
  // irequestFilter.push({'key':'z', 'value': '3'})
  async uploadDoc(formData, logout)

/////////////////////////////////

//service.js
import { BaseService } from 'base-service-fran-dev'
import { BASE_URL } from '../constants/constants'

export default class Service extends BaseService(){
  constructor(){
    const baseUrl = BASE_URL;
    const endpoint = "endpoint"
    super(baseUrl, endpoint);
  }
}
//////////////////////

//App.js

import Service from './service.js' //import service

async function functionName(){
    let Service = new Service();
    let response = await Service.postData({data})
}
logout()

License

MIT © fran-dev

About

baseservice is a class that contains all methods with or without auth. just create the instance and pass the data to the endpoint.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published