vibed-rest-axios 0.1.0

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


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

Coinmarketcap D API

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

Authors:
  • DarkRIDDeR
Dependencies:
vibe-d:inet, vibe-d:http, vibe-d:web
Versions:
0.1.0 2019-May-19
~master 2019-Jun-19
Show all 2 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 16 downloads total

Score:
0.9
Short URL:
vibed-rest-axios.dub.pm