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

react-atmo

v1.0.3

Published

A react renderer for express

Downloads

10

Readme

React atmo is a custom renderer for express js. This is an experimental project, supports very minimal features and not suitable for production apps. But it's a great fit for creating mock APIs for demos and presentations.

But, Why?

Beacause, Why not?

Getting Started

Start with the starter kit powered by backpack.

yarn add react-atmo

Hello, world!

import React from "react";
import Atmo, { Headers } from "../src";

Atmo.listen(
  <server port="9001">
    <middlewares>
      <bodyparser />
    </middlewares>
    <route method="get" url="/unicorns">
      <headers>
        <Headers.CrossOriginHeader />
        <Headers.JsonContentTypeHeader />
      </headers>
      <response>
        {() => ({
          name: "Adiana",
          description: "The fiery one"
        })}
      </response>
    </route>
  </server>
);

Have a look at the examples here.

API

Atmo.listen(element, [callback])

Starts an express server.

Elements

<server>

Creates a server app and starts listening on the provided port

port | Server port

<route>

Attaches the route to the express app

method | Http method name for the route.

url | Url of the route.

<response>

Represents the response of the route. Takes a function as a children. Whatever the function returns would be returned by the route.

Response function also receives request and response objects of express, if you want to do something interesting.

<response>
  {(request, response) => {
    // play with the request and response object of express
    return {
      status: 'alive'
    }
  }}
</response>

<headers>

Takes <header /> as children.

<header>

Represents a response header

<header name="x-powered-by" value="Unicorn JS" />

name | Header name

value | Header value

Save some typing and use the following header presets.

import Atmo, { Headers } from "react-atmo";
  • <Headers.JsonContentTypeHeader /> - Adds JSON content type header
  • <Headers.CrossOriginHeader /> - Adds Cross origin header

<status>

code | Satus code number

Should be a childen of the <route /> element.

Save some typing and use the following status presets.

import Atmo, { Status } from "react-atmo";
  • <Status.Ok /> - Code 200
  • <Status.Unauthorized /> - Code 401
  • <Status.BadRequest /> - Code 400
  • <Status.Forbidden /> - Code 403
  • <Status.NotFound /> - Code 404
  • <Status.InternalServerError /> - Code 500

<delay>

If you are creating a mock API and wants to simulate slowness, delay is the one you are looking for.

<delay time={1000} />

time | Delay in milliseconds.

<middlewares>

Accepts <middleware /> as children.

<static>

The static middleware.

<static path="./" />

path | Path of the folder to expose as static directory.

<bodyparser>

The body parser middleware.

<bodyparser />

<middleware>

Your own, custom middleware.

<middleware>
{app => {
  // use the app and do whatever you want
}}
</middleware>

<servers>

When you are not happy with a single instance and wants multiple apps listening on different ports.

import React, { Component } from "react";
import Atmo from "react-atmo";

Atmo.listen(
  <servers>
    <server port="9001">    
      <route method="get" url="/unicorns">
        <response>
          {() => ({
            name: "Adiana",
            description: "The fiery one"
          })}
        </response>
      </route>
    </server>
    <server port="9002">    
      <route method="get" url="/unicorns">
        <response>
          {() => ({
            name: "Adiana",
            description: "The fiery one, from server 2"
          })}
        </response>
      </route>
    </server>
  </servers>
);

Kitchen sink

import React, { Component } from "react";
import Atmo, { Headers, Status } from "react-atmo";

Atmo.listen(
  <server port="9001">
    <middlewares>
      <static path="./" />
      <bodyparser />
      <middleware>
        {app => {
          // use the app and do whatever you want
        }}
      </middleware>
    </middlewares>
    <route method="get" url="/unicorns">
      <headers>
        <Headers.CrossOriginHeader />
        <Headers.JsonContentTypeHeader />
        <header name="x-powered-by" value="Unicorn JS" />
      </headers>
      <response>
        {() => ({
          name: "Adiana",
          description: "The fiery one"
        })}
      </response>
      <delay time={3000} />
      <Status.Ok />
    </route>
  </server>
);

Inspiration and Reference

React-ionize is a react custom renderer which targets electron. I have used react-ionize as a reference to build react-atmo. Infact, I have used it as a boilerplate.