URL Encoder / Decoder

URL Encoder / Decoder API

Development

Percent-encode or decode URLs and query values as you type, with component, full-URL and form (+ for spaces) modes, clear errors, and a query-string breakdown.

Authentication

All API requests require a valid API key passed in the Authorization header as a Bearer token.

Rate Limit

120 requests per minute

Endpoints

1 endpoint available

Overview

Percent-encodes or decodes text, and breaks a URL or query string into its parts.

Modes

  • component (default) - like encodeURIComponent. For one value going into a URL, such as a search term or a path segment. Escapes everything except letters, digits and - _ . ! ~ * ' ( ), including / ? & = #.
  • uri - like encodeURI. For a whole URL. Keeps the characters that give a URL its structure and escapes spaces, non-ASCII letters and other unsafe characters. Decoding leaves escaped structure characters such as %2F alone.
  • form - application/x-www-form-urlencoded, as HTML forms send it. Spaces become +. Decoding turns + into a space.

Errors

Decoding stops at the first malformed escape and returns a 400 whose message says what is wrong and where. details.index is the zero-based position of the problem in text. Text with an unpaired UTF-16 surrogate cannot be encoded and also returns a 400. Percent-encoded bytes are read as UTF-8.

breakdown

breakdown is filled in when the input or the result is an absolute URL (with a scheme and ://) or a query string such as ?a=1&b=2. Otherwise it is null. url holds the parsed parts and params the query pairs, each with the decoded key and value and the raw rawKey and rawValue.

Limits

Up to 100,000 characters of text.

Endpoints

POST
https://opentools.ca/api/v1/tools/url-encoder-decoder
Percent-encode or decode text

Request Body

Content-Type: application/json

ParameterTypeRequiredDescription
text
string
Required
The text to encode or decode, 1 to 100,000 characters.
direction
string
Enum: encode, decode
Required
Whether to encode or decode.
mode
string
Enum: component, uri, form
OptionalEncoding style, described above.Default: component

Response Example

{
  "success": true,
  "direction": "encode",
  "mode": "uri",
  "result": "https://example.com/search?q=caf%C3%A9%20cr%C3%A8me&lang=fr",
  "breakdown": {
    "url": {
      "protocol": "https:",
      "username": "",
      "password": "",
      "hostname": "example.com",
      "port": "",
      "pathname": "/search",
      "hash": "",
      "origin": "https://example.com"
    },
    "params": [
      {
        "key": "q",
        "value": "café crème",
        "rawKey": "q",
        "rawValue": "caf%C3%A9%20cr%C3%A8me",
        "hasValue": true
      },
      {
        "key": "lang",
        "value": "fr",
        "rawKey": "lang",
        "rawValue": "fr",
        "hasValue": true
      }
    ]
  }
}

Error Codes

400
Bad Request - Missing or too long text, invalid direction or mode, a malformed % escape when decoding, or text that cannot be encoded
401
Unauthorized - Invalid or missing API key
403
Forbidden - API key is inactive or expired, or the request IP is not allowed for this key
429
Too Many Requests - Rate limit exceeded
500
Internal Server Error

Code Examples

# Encode a query value
curl -X POST https://opentools.ca/api/v1/tools/url-encoder-decoder \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "café crème & more", "direction": "encode", "mode": "component"}'

# Decode form data
curl -X POST https://opentools.ca/api/v1/tools/url-encoder-decoder \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "a+b%26c", "direction": "decode", "mode": "form"}'

Ready to get started?

Create an API key to start using the URL Encoder / Decoder API.

Rather use it in your browser? Open the URL Encoder / Decoder