Formatter
/api/v1

API documentation

One POST request formats a file. No key, no account, no signature — the address and a body are the whole contract.

Quick start

Minify a stylesheet and print the result:

curl
curl --data-urlencode 'input=.card { padding: 8px; margin: 0 auto; }' \
  https://formatter.nextwell.top/api/v1/minify/css/raw
# .card{padding:8px;margin:0 auto}

Swap {css} for {js} or {html}, and {minify} for {beautify}. Every combination works.

Endpoints

The base address is {base}. Everything below is a POST unless it says otherwise.

Method Path Purpose
POST/api/v1/minify/{lang}Minify, JSON response
POST/api/v1/minify/{lang}/rawMinify, plain-text response
POST/api/v1/beautify/{lang}Beautify, JSON response
POST/api/v1/beautify/{lang}/rawBeautify, plain-text response
GET/api/v1/limitsWhat this IP has left, without spending a request
GET/api/v1/healthLiveness check, never rate limited

{lang} is one of css, js or html.

Sending the code

Three body shapes are accepted on every endpoint — pick whichever your client makes easy.

Form encoded

An {input} field, {type}. This is the shape minifier APIs conventionally take, so an existing script only changes its address.

curl
curl --data-urlencode 'input=body{margin:0;padding:0}' \
  https://formatter.nextwell.top/api/v1/beautify/css

JSON

{type} with an {input} string.

curl
curl -H 'Content-Type: application/json' \
  -d '{"input":"const a=1;const b=a+1;console.log(b)"}' \
  https://formatter.nextwell.top/api/v1/beautify/js

Raw body

Any other content type: the body is the code. Convenient for {example}.

curl
curl --data-binary @style.css \
  -H 'Content-Type: text/css' \
  https://formatter.nextwell.top/api/v1/minify/css

Size

2 MB per request. Anything larger comes back as 413 without being read.

Query parameters

Name Values Meaning
indent 2 4 tab Beautify only: what one level of indentation is.
curl
curl --data-urlencode 'input=.a{color:red}' \
  'https://formatter.nextwell.top/api/v1/beautify/css?indent=tab'

The response

A successful call returns JSON:

JSON
{
  "ok": true,
  "action": "minify",
  "language": "css",
  "input_bytes": 1024,
  "output_bytes": 640,
  "saved_bytes": 384,
  "saved_percent": 37.5,
  "duration_ms": 42,
  "output": "p{color:red}"
}
Field Type Meaning
okbooleanAlways true on a success.
actionstringminify or beautify — what was asked for.
languagestringcss, js or html.
input_bytesnumberSize of what was sent, in bytes.
output_bytesnumberSize of the result, in bytes.
saved_bytesnumberThe difference; negative when beautifying.
saved_percentnumberThe same difference as a percentage, one decimal.
duration_msnumberHow long the work took, milliseconds.
outputstringThe formatted code.

Plain-text responses

Append {raw} to any format endpoint and the body is the result and nothing else, as {type}. The headers are the same. Useful when the caller is a shell:

curl
curl -s --data-binary @app.js \
  -H 'Content-Type: text/javascript' \
  https://formatter.nextwell.top/api/v1/minify/js/raw > app.min.js

Response headers

Header Meaning
X-Formatter-DurationProcessing time in milliseconds.
X-RateLimit-Remaining-Second … -MonthWhat is left in each window for this IP.
Retry-AfterOn a 429: seconds until the tightest spent window reopens.
curl
curl -s -D - -o /dev/null --data-urlencode 'input=.a{color:red}' \
  https://formatter.nextwell.top/api/v1/minify/css

Errors

Every error is JSON in the same shape:

JSON
{
  "errors": [
    { "status": 429, "title": "Too many requests", "detail": "…" }
  ]
}
Status Title When
400Missing input Bad requestNo body, or an empty input field.
404Not foundNo such path.
405Method not allowedA format endpoint was called with something other than POST.
413Payload too largeThe body is over 2 MB.
415Unsupported languageThe language in the path is not css, js or html.
422Malformed inputThe formatter refused the source — usually a syntax error — or took too long to process it.
429Too many requestsOne of the rate-limit windows is spent. Read Retry-After.
500Internal errorAnything else.

Rate limits

Per IP address, five rolling windows, all enforced at once. A request has to fit in all five.

Window Limit
Per second{n} requests
Per minute{n} requests
Per hour{n} requests
Per day{n} requests
Per month{n} requests

When a window is spent the answer is 429 with a Retry-After header giving the seconds until the tightest one reopens. Nothing is queued.

The counters live in a small database on disk, so restarting the service does not hand anyone a fresh day.

{endpoint} reports the current state of all five windows without spending one.

curl
curl https://formatter.nextwell.top/api/v1/limits

What is kept

Nothing. Your code is sent to our server, held in memory for the length of the request and dropped. It is not written to disk and never appears in a log. What the logs do carry: a truncated hash of the IP, the language, the action, the byte count and the duration.

Questions

Do I need a key?

No. The service is open and limited by IP address instead.

Is my code sent anywhere?

Only to our own server. Everything is processed there, in memory, and the code is neither stored nor logged.

Can I use it in a build script?

Yes, that is what the raw endpoints are for. Keep within the limits.

Why is my minified JavaScript renamed?

The minifier shortens local variable names, which is safe and is where most of the saving comes from. Beautifying will not bring the original names back — nothing can.

What is the largest file I can send?

2 MB in one request. Larger files are refused with 413 rather than truncated.