All Projects → meafmira → bs-axios

meafmira / bs-axios

Licence: other
Bucklescript bindings for axios

Programming Languages

reason
219 projects
HCL
1544 projects

Projects that are alternatives of or similar to bs-axios

reason-cookie
A simple way to use cookies in Reason (OCaml) on the frontend. 🍪
Stars: ✭ 18 (-75.68%)
Mutual labels:  reasonml
tea-chess
A chess-themed tutorial on writing an SPA in Bucklescript-TEA
Stars: ✭ 28 (-62.16%)
Mutual labels:  reasonml
vue-js-crud-laravel
Simple CRUD operations using Laravel and Vue.js
Stars: ✭ 27 (-63.51%)
Mutual labels:  axios
nibbledb
a byte-sized time series database
Stars: ✭ 23 (-68.92%)
Mutual labels:  reasonml
coronadev
Aplicativo para consultar a situação global do COVID-19
Stars: ✭ 44 (-40.54%)
Mutual labels:  axios
vue-ssr-template
A full-featured Webpack + vue-loader setup with hot reload, linting, testing & css extraction.. (Thanks for vue-hackernews-2.0)
Stars: ✭ 18 (-75.68%)
Mutual labels:  axios
serverless-reasonml
serverless framework plugin for writing functions with Reason
Stars: ✭ 13 (-82.43%)
Mutual labels:  reasonml
shrtn-it
A url shortener developed as a course completion project
Stars: ✭ 16 (-78.38%)
Mutual labels:  axios
electron-admin-antd-vue
Electron Vue3.x Ant Design Admin template
Stars: ✭ 21 (-71.62%)
Mutual labels:  axios
project-3-crm
⭐crm 客户关系管理系统模板⭐一个不错的后台管理种子项目,拥有自由设置角色自由分配权限🔑的权限管理功能,三员管理多员管理均可,前端antd vue admin后端spring-boot-api-seedling 拥有完善的功能。文档包含需求文档,设计文档和测试文档等。同时配置了travis,拥有集成测试和自动构建的功能。
Stars: ✭ 128 (+72.97%)
Mutual labels:  axios
add-my-name
No more WhatsApp spams 🎉
Stars: ✭ 16 (-78.38%)
Mutual labels:  axios
MQCMS-admin
MQCMS后台管理系统
Stars: ✭ 24 (-67.57%)
Mutual labels:  axios
axios-mock-server
RESTful mock server using axios.
Stars: ✭ 33 (-55.41%)
Mutual labels:  axios
re-use
⚛️ 🎣 A collection of hooks for ReasonReact
Stars: ✭ 27 (-63.51%)
Mutual labels:  reasonml
react admin
🎉 TS+Hooks 后台管理系统 http://hooks.sunhang.top
Stars: ✭ 39 (-47.3%)
Mutual labels:  axios
bs-react-fela
BuckleScript bindings for react-fela
Stars: ✭ 21 (-71.62%)
Mutual labels:  reasonml
shop-native
基于weex(vuejs),同时使用了vuex, vue-router, axios,包含异步(async)语法糖在安卓端不兼容的解决方案
Stars: ✭ 15 (-79.73%)
Mutual labels:  axios
react-ant-admin
此框架使用与二次开发,前端框架使用react,UI框架使用ant-design,全局数据状态管理使用redux,ajax使用库为axios。用于快速搭建中后台页面。
Stars: ✭ 52 (-29.73%)
Mutual labels:  axios
bs-reason-apollo
ReactApollo bindings for BS
Stars: ✭ 23 (-68.92%)
Mutual labels:  reasonml
react-jwt-auth
React JWT Authentication & Authorization example - React.js Login and Registration example
Stars: ✭ 307 (+314.86%)
Mutual labels:  axios

bs-axios npm version

Axios bindings for Bucklescript.

Installation

  1. Install bs-axios
$ yarn add bs-axios

or

$ npm install --save bs-axios
  1. Add "bs-axios" to "bs-dependencies" section of bsconfig.json

Examples

See usage examples in examples folder:

Simple request

Js.Promise.(
  Axios.get("/user?ID=12345")
  |> then_((response) => resolve(Js.log(response##data)))
  |> catch((error) => resolve(Js.log(error)))
);

Post requests

Js.Promise.(
  Axios.post("/user")
  |> then_((response) => resolve(Js.log(response##data)))
  |> catch((error) => resolve(Js.log(error)))
);
let user = {
  "username": "michel",
  "password": "12345678"
};

Js.Promise.(
  Axios.postData("/auth", {user})
  |> then_((response) => resolve(Js.log(response##data)))
  |> catch((error) => resolve(Js.log(error)))
);

Concurrency

Js.Promise.(
  Axios.all2((Axios.get("/users/1"), Axios.get("/users/1/friends")))
  |> then_(((user, friends)) => resolve(Js.log2(user##data, friends##data)))
  |> catch((error) => resolve(Js.log(error)))
);

Creating an instance

You can create a new instance of axios with a custom config.

open Axios;

let inst = Instance.create(makeConfig(~baseURL="https://example.com", ()));
Js.Promise.(Instance.get(inst, "/") |> then_((resp) => resolve(Js.log(resp##data))));

Error handling

external promiseErrorToJsObj : Js.Promise.error => Js.t('a) = "%identity";

Js.Promise.(
  Instance.get(inst, "/")
  |> then_(resp => resolve(Belt.Result.Ok(resp)))
  |> catch(error => {
       let error = error |> promiseErrorToJsObj;
       Js.log(error##response##status);
       resolve(Belt.Result.Error(error));
     })
);

Headers

let headers = Axios.Headers.fromObj({"Content-type": "application/json"});
Axios.getc("https://example.com", Axios.makeConfig(~headers, ()));

let headersDict =
  Js.Dict.(
    {
      let dict = empty();
      dict->set("Content-type", "application/json");
      dict;
    }
  );
let headers = Axios.Headers.fromDict(headersDict);
Axios.getc("https://example.com", Axios.makeConfig(~headers, ()));

Node.js HTTP/HTTPS Agent

Providing custom Node.js HTTP Agent allows for configuring connection persistence and reuse. For secure connections, HTTPS Agent allows security related configuration to be provided.

let httpsAgent =
  Axios.Agent.Https.(config(~rejectUnauthorized=false, ()) |> create);

Axios.getc(
  "https://insecure-example.com",
  Axios.makeConfig(~httpsAgent, ()),
);
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].