0.0.4 • Published 3 years ago

ragu-client-node v0.0.4

Weekly downloads
115
License
MIT
Repository
github
Last release
3 years ago

Ragu Client Node

Ragu Coverage Status License: MIT npm version PRs Welcome

A client for Ragu Server

You may need to fetch you micro-frontends at the server-side. This client is make for it!

Installation

$ npm install ragu-client-node

Usage

import RaguClient from 'ragu-client-node';

const client = new RaguClient();
const component = await client.fetchComponent('https://a-squad-ragu-server.organization.com/components/hello-world');

component.stylesheets(); // <style src="https://a-squad-ragu-server.organization.com/assets/hello-world.css"> 

component.html(); // html-content-from-server

component.toRaguDOM(); // <ragu-component src="https://a-squad-ragu-server.organization.com/components/hello-world">...html-content-from-server</ragu-component>

Fetch API

To be isomorphic friendly and dependency-free, Ragu Client Node uses fetch API. As node does not implement fetch API you will need a polyfill, such as cross-fetch and abort-controller.

$ npm install cross-fetch abort-controller

Registering polyfill:

require('cross-fetch/polyfill');
require('abort-controller/polyfill');

Ragu Node Client + Axios

If you already use axios as HTTP client you could use the ragu axios client.

import {RaguClient} from "ragu-node-client";
import {AxiosRequestAdapter} from "ragu-node-client/adapters/axios";

const client = new RaguClient({
  requestAdapter: new AxiosRequestAdapter()
});

Timout

You can specify a request timeout. The default is 5000ms. When a timeout occurs the fetchComponent promise will be reject with a new Error('Timeout') error.

const client = new RaguClient({
  timeout: 1000
});
0.0.4

3 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago