npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

api-mount

v1.0.13

Published

Library for making communication between front-end and back-end simple

Downloads

22

Readme

api-mount

by Vytenis Urbonavičius

api-mount provides a straightforward way for connecting Node.js based server with either browser or Node.js client.

Once setup, it makes it feel as if client is calling server-side API methods directly. HTTP requests are abstracted away.

Both Client and Server

api-mount has separate entry points for Node.js and browser environments. This prevents such situations as when Node.js logic ends up in the bundle meant for browser.

If, for some reason, you would want to explicitly install server-only or client-only package without the other part - you can do so. api-mount is actually fused out of 2 smaller packages which can be used independently:

  • api-mount-server - allows exposing API using api-mount protocol. Package contains detailed README about how APIs can be defined, exposed, how server can be configured, how protocol looks like, etc.
  • api-mount-client - allows mounting API which was previously exposed by api-mount-server. Package contains detailed README about how APIs can be consumed.

Using above packages directly have little benefit apart from saving few kilobytes of disk space on a development machine - build size should not be impacted.

Installation

npm install --save api-mount

Usage Example

If you are not yet an experienced JS/TS developer, you might find "Try it out" section of api-mount-client documentation useful.

api-mount when used in Node.js environment contains exact methods of both api-mount-server and api-mount-client. Please see detailed documentation by clicking on these package names.

Below code serves only as an example:

import {apiMountFactory, mountApi} from 'api-mount'

const serverApi = {
  test: () => 'hello',
}

// Serving API on localhost:3000
const ApiMount = apiMountFactory()
ApiMount.exposeApi(serverApi)

// Mounting API which has just been served above
const clientApi = mountApi({baseUrl: 'http://localhost:3000'})
await clientApi.test() // 'hello'

Notice that in the above example apiMountFactory comes from api-mount-server while mountApi comes from api-mount-client.