Search Trains
GET
GET /v1/trains/search?q=&limit=Description
Find trains by number or partial name in one request. Returns matching trains with their number, name and origin/destination codes plus the result count.
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
q | QUERY | string | YES | Query param — train number or partial name, e.g. rajdhani. |
limit | QUERY | number | NO | Query param — maximum number of results to return. |
Code Example
javascript
const res = await fetch(
"https://railway-engine.apkscope.workers.dev/v1/trains/search?q=rajdhani&limit=5",
{ headers: { "x-api-key": "YOUR_KEY" } },
);
const { status, data, error } = await res.json();
if (status === "SUCCESS") {
console.log(data.count, "matches");
for (const train of data.results) {
console.log(train.number, train.name, train.originCode, "→", train.destinationCode);
}
} else {
console.error(status, error?.code, error?.message);
}Notes
Errors: 400 INVALID_REQUEST (missing or too-short q), 404 NOT_FOUND when nothing matches, 429 RATE_LIMITED. `limit` caps the result size; `count` is the number of results actually returned.
Response Example