Skip to content


Install package react <project name>

Initialize API object

For example in api.js

import React from 'react'
import { API } from '@freenit-framework/axios'

export const api = new API()

Use it in a component

import React from 'react'
import { api } from 'api'

class App extends React.Component {
  state = {
    users: [],

  constructor(props) {

  fetch = async () => {
    const response = await api.user.getList()
    if (response.ok) {
      this.setState({ users: })
    } else {
      console.log('error in App', api.errors(response).message)

  render() {
    return (
        <h1>Freenit User List</h1>
        { => (
          <div key={}>{}</div>


API accepts two parameters: prefix and config. Prefix is what axios calls baseURL and by default is /api/v0. If you want to further customize axios you can pass config object like so const api = new API('/api/v1', { withCredentials: false }). All axios config params are supported.

API also has 3 objects, one for auth, me and user. That means you can call

await api.auth.login('', 'Sekrit')
await{ email: '' })
to login and change your email.

API Reference

This is the full list of supported calls:


  • login
  • logout


  • get
  • patch


  • get
  • getList
  • patch
  • post
  • delete

If you need to implement call to new endpoint

const doit = async () => {
  return await api.get('/some/endpoint')
What it returns is either data that came with the response or the error object. If you need access to underlaying axios object use api.api instead of api.