vibed-rest-axios

Generator of Rest API JS ES6 client with Axios for Vibe.d


License
Apache-2.0
Install
dub fetch vibed-rest-axios --version 0.1.0

Documentation

Vibe.d Rest Axios

Generator of Rest API JS ES6 client with Axios for Vibe.d

Install

$ dub add vibed-rest-axios

Example

import vibed_rest_axios;

void main()
{
	import vibe.inet.url;
	import vibe.http.common;
	import vibe.web.rest;

	interface S {
		void test();
	}

	interface I {
		@property S s();
		int test1();
		void test2();

		// GET /compute_sum?a=...&b=...
		@method(HTTPMethod.GET)
		float computeSum(float a, float b);

		// POST /to_console {"text": ...}
		void postToConsole(string text);
	}

	auto restsettings = new RestInterfaceSettings;
	restsettings.baseURL = URL("http://127.0.0.1:8080/");
	genRestAxios!I(restsettings, "./result");
}

Result in file "./result/I.js"":

import axios from 'axios'

const toRestString = (v) => {
  if (typeof(v) === "object") v = JSON.stringify(v);
  return encodeURIComponent(v);
}

const I = {
's': {   'test': () => {
    return axios({
      method: 'POST',
      url: 'http://127.0.0.1:8080/s/test'
    })
  } },
  'test1': () => {
    return axios({
      method: 'POST',
      url: 'http://127.0.0.1:8080/test1'
    })
  },
  'test2': () => {
    return axios({
      method: 'POST',
      url: 'http://127.0.0.1:8080/test2'
    })
  },
  'computeSum': (a,b) => {
    return axios({
      method: 'GET',
      url: 'http://127.0.0.1:8080/compute_sum' + "?a=" + toRestString(a) + "&b=" + toRestString(b)
    })
  },
  'postToConsole': (text) => {
    return axios({
      method: 'POST',
      url: 'http://127.0.0.1:8080/to_console',
      data: {"text": text}
    })
  }
}

export default I

License

Apache 2.0