Skip to main content

Getting Started

Quick start guide to install and use fast-url in your JavaScript or TypeScript project
2 min read

Installation#

Install fast-url using your preferred package manager:

Note

TypeScript Support

fast-url is written in TypeScript and includes type definitions out of the box. No need to install separate @types packages!

Basic Usage#

Importing#

Quick Examples#

Here are some common use cases to get you started:

Path Parameters#

Replace placeholders in a URL path with actual values:

Query Parameters#

Add query string parameters to a URL:

Combined Path and Query Parameters#

Mix path substitution with query parameters:

Step-by-Step Tutorial#

Let's build a simple REST API client using fast-url:

Create the API Client Class#

Start by creating a basic API client structure:

Add a Method to Fetch Posts#

Use createUrl to build the endpoint URL with query parameters:

Add a Method to Fetch a Single Post#

Use path parameters for resource IDs:

Use the API Client#

Now you can use your API client with clean, type-safe URLs:

Common Patterns#

Handling Optional Parameters#

fast-url automatically filters out null and undefined values:

Working with Arrays#

Arrays are automatically converted to repeated parameters:

Building Query Strings Only#

Use the query helper when you only need a query string:

Substituting Path Parameters Only#

Use subst when you only need path parameter substitution:

Joining URL Parts#

Use join to safely concatenate URL segments:

Special Characters and Unicode#

fast-url properly handles special characters and Unicode:

Error Handling#

fast-url validates path parameters and throws helpful errors:

Check

Type Safety

When using TypeScript, many of these errors can be caught at compile time thanks to fast-url's type definitions!