All Projects → mpyw → axios-case-converter

mpyw / axios-case-converter

Licence: MIT license
Axios transformer/interceptor that converts snake_case/camelCase

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to axios-case-converter

fetchx
Beautiful way to fetch data in React
Stars: ✭ 71 (-37.72%)
Mutual labels:  http-client, axios
Redux Axios Middleware
Redux middleware for fetching data with axios HTTP client
Stars: ✭ 902 (+691.23%)
Mutual labels:  http-client, axios
go-axios
HTTP Request package for golang.
Stars: ✭ 29 (-74.56%)
Mutual labels:  http-client, axios
axios-for-observable
A RxJS wrapper for axios, same api as axios absolutely
Stars: ✭ 13 (-88.6%)
Mutual labels:  http-client, axios
camelcaseplugin
CamelCasePlugin for IDEA IDEs
Stars: ✭ 49 (-57.02%)
Mutual labels:  snake-case, camelcase
http-interceptors
The Web apps in this monorepo make HTTP requests and require uniform consistency in how they are executed and handled. This monorepo demonstrates the same app written with Angular and with Svelte. Each app uses HTTP interceptors. The Angular app uses HttpClient and its interceptors while the Svelte app uses Axios and its interceptors.
Stars: ✭ 46 (-59.65%)
Mutual labels:  http-client, axios
Redux Requests
Declarative AJAX requests and automatic network state management for single-page applications
Stars: ✭ 330 (+189.47%)
Mutual labels:  http-client, axios
recase
♻️ Convert strings to any case.
Stars: ✭ 183 (+60.53%)
Mutual labels:  snake-case, camelcase
Rxios
A RxJS wrapper for axios
Stars: ✭ 119 (+4.39%)
Mutual labels:  http-client, axios
Use Axios Request
Data fetching is easy with React Hooks for axios!
Stars: ✭ 38 (-66.67%)
Mutual labels:  http-client, axios
Saber
⚔️ Saber, PHP异步协程HTTP客户端 | PHP Coroutine HTTP client - Swoole Humanization Library
Stars: ✭ 866 (+659.65%)
Mutual labels:  http-client, axios
cute-http
一个基于axios封装的更易用的http库。
Stars: ✭ 18 (-84.21%)
Mutual labels:  http-client, axios
python-string-utils
A handy Python library to validate, manipulate and generate strings
Stars: ✭ 47 (-58.77%)
Mutual labels:  snake-case, camelcase
stringy
Convert string to camel case, snake case, kebab case / slugify, custom delimiter, pad string, tease string and many other functionalities with help of by Stringy package.
Stars: ✭ 137 (+20.18%)
Mutual labels:  snake-case, camelcase
mobxSpa
企业级SPA项目,完整开发脚手架
Stars: ✭ 96 (-15.79%)
Mutual labels:  axios
requester
The package provides a very thin wrapper (no external dependencies) for http.Client allowing the use of layers (middleware).
Stars: ✭ 14 (-87.72%)
Mutual labels:  http-client
Curio
A Blazing Fast HTTP Client
Stars: ✭ 35 (-69.3%)
Mutual labels:  http-client
fptu-app
FUHCM Universal Web App based on Node.js & React
Stars: ✭ 17 (-85.09%)
Mutual labels:  axios
hunt-http
http library for D, support http 1.1 / http 2.0 (http2) / websocket server and client.
Stars: ✭ 29 (-74.56%)
Mutual labels:  http-client
TimeTableManager
Simple react application to create a TimeTable based only on your choice of subjects.
Stars: ✭ 30 (-73.68%)
Mutual labels:  axios

axios-case-converter

npm version Build Status Coverage Status

Axios transformer/interceptor that converts snake_case/camelCase

  • Converts outgoing data params object keys into snake_case
  • Converts incoming data object keys into camelCase
  • Converts outgoing headers object keys into Header-Case
  • Converts incoming headers object keys into camelCase

Installing

NPM

npm install axios-case-converter

CDN

<script src="https://unpkg.com/axios-case-converter@latest/dist/axios-case-converter.min.js"></script>

It is strongly recommended that you replace latest with a fixed version.

Usage

You can fully use camelCase in your JavaScript codes.

import applyCaseMiddleware from 'axios-case-converter';
import axios from 'axios';

(async () => {
  const client = applyCaseMiddleware(axios.create());
  const { data } = await client.post(
    'https://example.com/api/endpoint',
    {
      targetId: 1
    },
    {
      params: { userId: 1 },
      headers: { userAgent: 'Mozilla' }
    }
  );

  console.log(data.actionResult.users[0].screenName);
})();

Options

const client = applyCaseMiddleware(axios.create(), options);

preservedKeys: string[] | Function

Disable transformation when the string matched or satisfied the condition.

const options = {
  preservedKeys: ['preserve_this_key_1', 'preserve_this_key_2']
};
const options = {
  preservedKeys: (input) => {
    return ['preserve_this_key_1', 'preserve_this_key_2'].includes(input);
  }
};

ignoreHeaders: boolean

Disable HTTP headers transformation.

const options = {
  ignoreHeaders: true
};

caseFunctions: { snake?: Function, camel?: Function, header?: Function }

Override built-in change-case functions.

const options = {
  caseFunctions: {
    camel: (input, options) => {
      return (input.charAt(0).toLowerCase() + input.slice(1)).replace(/[-_](.)/g, (match, group1) => group1.toUpperCase());
    }
  }
};

caseOptions: { stripRegexp?: RegExp }

By default, { stripRegexp: /[^A-Z0-9[\]]+/gi } is used as default change-case function options. This preserves [] chars in object keys. If you wish keeping original change-case behavior, override the options.

const options = {
  caseOptions: {
    stripRegexp: /[^A-Z0-9]+/gi
  }
};

caseMiddleware: { requestTransformer?: Function, responseTransformer?: Function, requestInterceptor?: Function }

Totally override axios-case-converter behaviors.

const options = {
  caseMiddleware: {
    requestInterceptor: (config) => {
      // Disable query string transformation
      return config;
    }
  }
};
Check the tests for more info

Attention

Object compatibility

If you run on Internet Explorer, you need polyfill for Object.prorotypte.entries().

FormData compatibility

If you use FormData on Internet Explorer, you need polyfill of FormData.prototype.entries().

If you use FormData on React Native, please ignore the following warnings after confirming that polyfill is impossible.

// RN >= 0.52
import { YellowBox } from 'react-native';
YellowBox.ignoreWarnings([
  'Be careful that FormData cannot be transformed on React Native.'
]);

// RN < 0.52
console.ignoredYellowBox = [
  'Be careful that FormData cannot be transformed on React Native.'
];

Symbol compatibility

If you use React Native for Android development, you should use Symbol polyfill from core-js to avoid bugs with iterators:

  1. Create polyfill.js in root directory with code:
global.Symbol = require('core-js/es6/symbol');
require('core-js/fn/symbol/iterator');
  1. Include polyfill.js in entry point of your app (e.g. app.js):
import { Platform } from 'react-native';

// ...

if (Platform.OS === 'android') {
  require('./polyfill.js');
}

cf. undefined is not a function(evaluating '_iterator[typeof Symbol === "function"?Symbol.iterator:"@@iterator"]()') · Issue #15902 · facebook/react-native

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].