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

semserver

v1.0.0

Published

<h1 align="center"> <img width="600" alt="Semserver" src="images/logo.png"><br> <sup>microservice semver registry</sup> </h1>

Downloads

325

Readme

Register a service version

> POST /my-service/1.0.0
>
> endpoint=http://my-service-adsfghjk.now.sh

and you can query it:

> GET /my-service/^1.0.0/thing/1

< HTTP/1.1 307 Temporary Redirect
< Location: http://my-service-adsfghjk.now.sh/thing/1

Register another version

> POST /my-service/1.1.0
>
> endpoint=http://my-service-zxcvbnm.now.sh

and you get the latest that satisfies the range:

> GET /my-service/^1.0.0/thing/1

< HTTP/1.1 307 Temporary Redirect
< Location: http://my-service-zxcvbnm.now.sh/thing/1

Server

Running

Run npm start. The server listens on port 7888 by default.

Deployment

Semserver runs as-is on now.sh. Run now in the folder to deploy it.

Authentication

If you want to prevent unauthorized users from registering services, start Semserver with an APIKEY environment variable, e.g. APIKEY=abcdef npm start, or deploy it with now -e APIKEY=abcdef. If the variable is set, requests to register a service will return a 401 Unauthorized unless you send an Authorization: Token [apikey] header.

Endpoints

POST /:service/:version

URL parameter | Description --------------|-------------- service | The name of the service you're registering version | The version of the service you're registering. Must be a valid Semver version.

Post parameter | Description ---------------|-------------- endpoint | The HTTP endpoint for this version of the service

Registers a version of a service. Once registered, the version is immutable and will always point to this endpoint. Trying to register the same version again will return a 409 Conflict.

Status code | Description ------------|-------------- 400 | The version is not a valid semver string 409 | The version already exists for this service

OPTIONS /:service

Returns an object listing the registered versions of the service and their endpoints.

* /:service/:versionOrRange/:path

URL parameter | Description --------------|-------------- service | The name of the service you're requesting version | The version of the service you're requesting. Must be a valid Semver version or version range. path | The path you're requesting of the service

Resolves a service version and issues a redirect to its endpoint.

If you provide an exact version (e.g. 1.2.3), you'll get a 308 Permanent Redirect. Service versions are immutable, so you can guarantee this version will always have this endpoint.

If instead you provide a semver range (e.g. 1.x.x, ^1.0.0), you'll get a 307 Temporary Redirect. Semserver resolves the highest version of the service that matches your version range and redirects to its endpoint.

Status code | Description ------------|-------------- 307 | Temporary redirect to the highest service version that matches the version range 308 | Permanent redirect to the exact version requested 400 | The version is not a valid semver range string 404 | The service doesn't exist in the registry at all 501 | The service has no versions that match the range or exact version you wanted

Command line

So you can automatically register a service to a registry (e.g. on deploy), we provide a command line script. It's intended to be used as an npm script, and it takes your service name and version from package.json, as well as the registry host, which you should put in package.json as "semserver": {"host": "semserver.example.com"}. Finally, pass the endpoint you're registering as the single command line argument.

For example, if you're deploying to now.sh, you can use the now-build lifecycle script to register your service. Now provides the NOW_URL environment variable, so your package.json should look like:

{
	"name": "my-service",
	"version": "1.0.0",
	"scripts": {
		"now-start": "...",
		"now-build": "semserver $NOW_URL"
	},
	"dependencies": {
		"semserver": "^1.0.0"
	},
	"semserver": {
		"host": "semserver.example.com"
	}
}

If your semserver has an API key configured, use the environment variable SEMSERVER_KEY to tell the CLI about it.

Client library

We also provide a client library, which is a thin wrapper around got.

Usage

const semserver = require('semserver');
const registry = semserver('https://semserver.example.com');
const service = registry('my-service', '^1.0.0');

service('/thing/1').then(...);

Licence

ISC. © Matt Brennan