Semver API
Parse and validate semantic versions, compare them, check npm-style ranges (^, ~, x, ||), sort lists and compute the next major / minor / patch / pre-release.
The semver API applies the rules of npm’s semver package, the reference implementation of Semantic Versioning 2.0.0. With version it parses a version (major, minor, patch, pre-release and build parts), compares it with compare= (lower / higher / equal and which part differs), tests it against a range such as ^1.2.0, ~3.4, >=2 <3, 1.x || 2.x or 1.2.3 - 2.0.0, and lists the next version for every release type.
With versions (an array or a comma-separated list) it sorts them, reports invalid entries, returns the latest and latest stable version and, with a range, the versions that satisfy it and the highest and lowest matches, which is how package managers pick a version.
coerce=true turns loose input such as v2, 1.2 or release-3.4.1 into a valid version; pre-releases only match ranges that mention them unless include_prerelease=true.
Parameters
| Name | In | Type | Required | Default | |
|---|---|---|---|---|---|
version | query|body | string | no | A version to parse. | |
compare | query|body | string | no | Another version to compare with. | |
range | query|body | string | no | npm range, e.g. ^1.2.0. | |
versions | query|body | string | no | List to sort / filter (array or comma-separated). | |
bump | query|body | string | no | major, minor, patch, premajor, preminor, prepatch, prerelease. | |
coerce | query|body | boolean | no | false | Accept loose input (v2, 1.2). |
include_prerelease | query|body | boolean | no | false | Let ranges match pre-releases. |
Example
curl "https://apibox.io.vn/v1/semver?versions=1.0.0,2.0.0-rc.1,1.10.0,1.2.0&range=>=1.2 <2" \
-H "Authorization: Bearer YOUR_API_KEY"const res = await fetch('https://apibox.io.vn/v1/semver?versions=1.0.0,2.0.0-rc.1,1.10.0,1.2.0&range=>=1.2 <2', {
method: 'GET',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
},
});
const data = await res.json();
console.log(data);import requests
res = requests.get(
"https://apibox.io.vn/v1/semver?versions=1.0.0,2.0.0-rc.1,1.10.0,1.2.0&range=>=1.2 <2",
headers={"Authorization": "Bearer YOUR_API_KEY"},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/semver?versions=1.0.0,2.0.0-rc.1,1.10.0,1.2.0&range=>=1.2 <2');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY'],
]);
$response = curl_exec($ch);
print_r(json_decode($response, true));Response
{
"count": 4,
"sorted": [
"1.0.0",
"1.2.0",
"1.10.0",
"2.0.0-rc.1"
],
"invalid": [],
"latest": "2.0.0-rc.1",
"latest_stable": "1.10.0",
"range": ">=1.2 <2",
"normalized_range": ">=1.2.0 <2.0.0-0",
"satisfying": [
"1.10.0",
"1.2.0"
],
"max_satisfying": "1.10.0",
"min_satisfying": "1.2.0"
}
Use cases
- Update checks in apps and CLIs
- Release automation: compute the next version
- Dependency dashboards: which versions satisfy a range
- Sort tags and releases correctly (1.10 after 1.9)
FAQ
What does ^1.2.3 allow?
Any version >=1.2.3 and <2.0.0. For 0.x versions the caret is stricter: ^0.2.3 means >=0.2.3 <0.3.0.
Why does 2.0.0-rc.1 not satisfy >=1.0.0?
By npm rules pre-releases only match comparators that have a pre-release on the same version. Use include_prerelease=true to include them.
Why is 1.10.0 after 1.9.0?
Each part is compared as a number, unlike plain string sorting.
Related APIs
UUID Generator
Generate up to 1,000 UUID v4, time-ordered UUID v7, ULID, Nano ID or random hex IDs per request. Secure randomness, optional uppercase.
⏱Cron Expression Parser
Validate a cron expression and get its next run times in any timezone, with a plain-English description. Supports 5, 6 and 7-field cron syntax.
🕒Time & Timezone Converter
Get the current time in any timezone, convert between timezones and Unix timestamps (seconds or ms), with UTC offset and weekday for up to 30 zones.