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

arc-plugin-named-routes

v1.2.1

Published

Named routes for Architect HTTP functions

Downloads

5

Readme

arc-plugin-named-routes

Named routes for Architect HTTP functions

Install

Into your existing Architect project:

npm i arc-plugin-named-routes

Add the following to your Architect project manifest (usually app.arc):

@plugins
arc-plugin-named-routes

Then modify any HTTP routes you wish to name to the verbose format and add a name:

@http
/foo
  method get
  name foo

Usage

Import the route() helper in to an HTTP function Lambda to use named routes:

// src/http/get-index/index.js
const route = require('arc-plugin-named-routes/route')

exports.handler = async () => ({
  statusCode: 200,
  headers: {
    'content-type': 'text/html; charset=utf8'
  },
  body: `
    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
      <a href="${route('foo')}">Foo</a>
    </body>
    </html>
  `,
})

You must pass path parameters to route() if they exist in the route's path:

@http
/foo/:id
  method get
  name foo
route('foo', { id: 123 })

// returns: /foo/123

Any properties of the supplied object that do not match a path property are appended to the route in a query string:

route('foo', { id: 123, bar: 'bar' })

// returns: /foo/123?bar=bar

You can use the same name for two or more routes as long as each route has a unique method. The helper function will default to GET, then ANY. You can optionally supply an alternative method as the first argument:

@http
/foo/:id
  method get
  name foo
/bar
  method post
  name foo
route('foo', { id: 123 })

// returns: /foo/123

route('get', 'foo', { id: 123 })

// returns: /foo/123

route('post', 'foo')

// returns: /bar

When refactoring routes, to ease migration you can define multiple names for a single route (assuming no duplication, as above):

@http
/foo
  method get
  name foo bar
route('foo')

// returns: /foo

route('bar')

// returns: /foo

Configuration

If you wish to use the plugin for routes that are external to the current application, you can configure them using the @named-routes pragma in app.arc:

@named-routes
testing
  foo http://localhost:9876/foo/:id
staging
  foo https://example.org/foo/:id

Routes are defined against a stage. You can use path parameters in the usual way.

External routes will be interpreted as ANY method routes and prefixed with external.:

route('external.foo', { id: 123 })

// returns: http://localhost:9876/foo/123 in testing and https://example.org/foo/123 in staging