⚡
light
  • light
  • guides
    • getting started
    • server vs serverless
    • routes
    • models
    • factories
    • routing
    • plugins
    • middleware
    • query
    • params
    • global
    • error handling
    • hot module reloading (TODO)
    • databases (TODO)
      • mongoose
      • objection/knex
    • testing (TODO)
      • ava
      • jest
    • deployments (TODO)
      • runkit
      • aws
      • now
      • heroku
      • server
      • google cloud
      • azure
      • netlify
    • misc (TODO)
      • apollo/graphql
  • api
    • server({ routes, opts }): object
    • params(path, url): Promise<object>
    • boom
      • Coming soon
    • micro
      • Coming soon
      • Coming soon
      • Coming soon
      • Coming soon
      • Coming soon
      • Coming soon
Powered by GitBook
On this page
  • Output
  • Parameters
  • path: string
  • url: string

Was this helpful?

  1. api

params(path, url): Promise<object>

Previousserver({ routes, opts }): objectNextboom

Last updated 5 years ago

Was this helpful?

params is a function used to parse url params out of a given url. It takes in a template and the actual URL and compares the two to return an object mapping of name to value.

Output

This function returns a promise object based on the input. For example, await params('/posts/:id', '/posts/123'); will return:

{
  id: '123',
}

Parameters

This function takes in two strings, the path (template) and url (actual url).

path: string

A template string containing the positions of the parameters as defined by the documentation.

'/posts/:id';

url: string

The URL of the current route being processed, usually found with req.url.

'/posts/123'; // req.url
find-my-way