ragu-client-node
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

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
});

Readme

Keywords

none

Package Sidebar

Install

npm i ragu-client-node

Weekly Downloads

5

Version

0.0.4

License

MIT

Unpacked Size

52.7 kB

Total Files

26

Last publish

Collaborators

  • carlosmaniero