torrust / torrust-tracker

A modern and feature-rich (private) BitTorrent tracker.
https://torrust.com
GNU Affero General Public License v3.0
370 stars 44 forks source link

API V2: new API with the correct response codes #144

Open josecelano opened 1 year ago

josecelano commented 1 year ago

Parent issue: https://github.com/torrust/torrust-tracker/issues/141 It depends on: https://github.com/torrust/torrust-tracker/issues/143

We start building a new API using the /v2 prefix. For example: /v2/api/stats. We can use the same URLs but change the response codes.

Change the response codes to the right one: 200, 201, 404, etcetera. Right now, it only uses 200 and 500.

Potential changes

I think we could make other changes:

Notes

Long-term changes

These are changes not included in this issue, but they should be considered in future versions.

josecelano commented 1 year ago

@da2ce7 @WarmBeer

I've found this interesting issue https://github.com/tokio-rs/axum/issues/50 where people are asking Axum to add support for generating OpenAPI/Swagger docs.

And some mentioned that you could use utopia. It has support for all the major web frameworks.

josecelano commented 9 months ago

The rqbit - bittorrent client in Rust uses this very useful API entrypoint:

{
  "apis": {
    "GET /": "list all available APIs",
    "GET /dht/stats": "DHT stats",
    "GET /dht/table": "DHT routing table",
    "GET /torrents": "List torrents (default torrent is 0)",
    "GET /torrents/{index}": "Torrent details",
    "GET /torrents/{index}/haves": "The bitfield of have pieces",
    "GET /torrents/{index}/peer_stats": "Per peer stats",
    "GET /torrents/{index}/stats/v1": "Torrent stats",
    "GET /web/": "Web UI",
    "POST /rust_log": "Set RUST_LOG to this post launch (for debugging)",
    "POST /torrents": "Add a torrent here. magnet: or http:// or a local file.",
    "POST /torrents/{index}/delete": "Forget about the torrent, remove the files",
    "POST /torrents/{index}/forget": "Forget about the torrent, keep the files",
    "POST /torrents/{index}/pause": "Pause torrent",
    "POST /torrents/{index}/start": "Resume torrent"
  },
  "server": "rqbit",
  "version": "5.4.1"
}

cc @da2ce7