-
Notifications
You must be signed in to change notification settings - Fork 528
feat: better api docs #6586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fetchfern
wants to merge
7
commits into
main
Choose a base branch
from
fetch/nicer-docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+5,442
−1,014
Open
feat: better api docs #6586
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4f67775
feat: docs
fetchfern d0e8edb
fix tombi
fetchfern dd3f0ec
chore: fix some of the routes rendering with missing /
fetchfern b0e9c56
response schemas
fetchfern 7f8c7f8
fix: restore labrinth docs routes
fetchfern bd17856
Fix path parameter docs in routes
aecsocket d4c6466
remove utoipa-actix-web
fetchfern File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| API v2 is Modrinth's official API. It is the recommended API for integrations and applications, and it will receive long-term support. | ||
|
|
||
| ## Authentication | ||
| This API has two options for authentication: personal access tokens and [OAuth2](https://en.wikipedia.org/wiki/OAuth). | ||
| All tokens are tied to a Modrinth user and use the `Authorization` header of the request. | ||
|
|
||
| Example: | ||
| ``` | ||
| Authorization: mrp_RNtLRSPmGj2pd1v1ubi52nX7TJJM9sznrmwhAuj511oe4t1jAqAQ3D6Wc8Ic | ||
| ``` | ||
|
|
||
| You do not need a token for most requests. Generally speaking, only the following types of requests require a token: | ||
| - those which create data (such as version creation) | ||
| - those which modify data (such as editing a project) | ||
| - those which access private data (such as draft projects, notifications, emails, and payout data) | ||
|
|
||
| Each request requiring authentication has a certain scope. For example, to view the email of the user being requested, the token must have the `USER_READ_EMAIL` scope. | ||
| You can find the list of available scopes [on GitHub](https://github.com/modrinth/labrinth/blob/master/src/models/pats.rs#L15). Making a request with an invalid scope will return a 401 error. | ||
|
|
||
| Please note that certain scopes and requests cannot be completed with a personal access token or using OAuth. | ||
| For example, deleting a user account can only be done through Modrinth's frontend. | ||
|
|
||
| A detailed guide on OAuth has been published in [Modrinth's technical documentation](https://docs.modrinth.com/guide/oauth). | ||
|
|
||
| ### Personal access tokens | ||
| Personal access tokens (PATs) can be generated in from [the user settings](https://modrinth.com/settings/account). | ||
|
|
||
| ### GitHub tokens | ||
| For backwards compatibility purposes, some types of GitHub tokens also work for authenticating a user with Modrinth's API, granting all scopes. | ||
| **We urge any application still using GitHub tokens to start using personal access tokens for security and reliability purposes.** | ||
|
|
||
| ## Cross-Origin Resource Sharing | ||
| This API features Cross-Origin Resource Sharing (CORS) implemented in compliance with the [W3C spec](https://www.w3.org/TR/cors/). | ||
| This allows for cross-domain communication from the browser. | ||
| All responses have a wildcard same-origin which makes them completely public and accessible to everyone, including any code on any site. | ||
|
|
||
| ## Identifiers | ||
| The majority of items you can interact with in the API have a unique eight-digit base62 ID. | ||
| Projects, versions, users, threads, teams, and reports all use this same way of identifying themselves. | ||
| Version files use the sha1 or sha512 file hashes as identifiers. | ||
|
|
||
| Each project and user has a friendlier way of identifying them; slugs and usernames, respectively. | ||
| While unique IDs are constant, slugs and usernames can change at any moment. | ||
| If you want to store something in the long term, it is recommended to use the unique ID. | ||
|
|
||
| ## Ratelimits | ||
| The API has a ratelimit defined per IP. Limits and remaining amounts are given in the response headers. | ||
| - `X-Ratelimit-Limit`: the maximum number of requests that can be made in a minute | ||
| - `X-Ratelimit-Remaining`: the number of requests remaining in the current ratelimit window | ||
| - `X-Ratelimit-Reset`: the time in seconds until the ratelimit window resets | ||
|
|
||
| Ratelimits are the same no matter whether you use a token or not. | ||
| The ratelimit is currently 300 requests per minute. If you have a use case requiring a higher limit, please [contact us](mailto:support@modrinth.com). | ||
|
|
||
| ## User Agents | ||
| To access the Modrinth API, you **must** use provide a uniquely-identifying `User-Agent` header. | ||
| Providing a user agent that only identifies your HTTP client library (such as "okhttp/4.9.3") increases the likelihood that we will block your traffic. | ||
| It is recommended, but not required, to include contact information in your user agent. | ||
| This allows us to contact you if we would like a change in your application's behavior without having to block your traffic. | ||
| - Bad: `User-Agent: okhttp/4.9.3` | ||
| - Good: `User-Agent: project_name` | ||
| - Better: `User-Agent: github_username/project_name/1.56.0` | ||
| - Best: `User-Agent: github_username/project_name/1.56.0 (launcher.com)` or `User-Agent: github_username/project_name/1.56.0 (contact@launcher.com)` | ||
|
|
||
| ## Versioning | ||
| Modrinth follows a simple pattern for its API versioning. | ||
| In the event of a breaking API change, the API version in the URL path is bumped, and migration steps will be published below. | ||
|
|
||
| API v2 is the current official API and will receive long-term support. | ||
|
|
||
| ### Migrations | ||
| Inside the following spoiler, you will be able to find all changes between versions of the Modrinth API, accompanied by tips and a guide to migrate applications to newer versions. | ||
|
|
||
| Here, you can also find changes for [Minotaur](https://github.com/modrinth/minotaur), Modrinth's official Gradle plugin. Major versions of Minotaur directly correspond to major versions of the Modrinth API. | ||
|
|
||
| <details><summary>API v1 to API v2</summary> | ||
|
|
||
| These bullet points cover most changes in the v2 API, but please note that fields containing `mod` in most contexts have been shifted to `project`. For example, in the search route, the field `mod_id` was renamed to `project_id`. | ||
|
|
||
| - The search route has been moved from `/api/v1/mod` to `/v2/search` | ||
| - New project fields: `project_type` (may be `mod` or `modpack`), `moderation_message` (which has a `message` and `body`), `gallery` | ||
| - New search facet: `project_type` | ||
| - Alphabetical sort removed (it didn't work and is not possible due to limits in MeiliSearch) | ||
| - New search fields: `project_type`, `gallery` | ||
| - The gallery field is an array of URLs to images that are part of the project's gallery | ||
| - The gallery is a new feature which allows the user to upload images showcasing their mod to the CDN which will be displayed on their mod page | ||
| - Internal change: Any project file uploaded to Modrinth is now validated to make sure it's a valid Minecraft mod, Modpack, etc. | ||
| - For example, a Forge 1.17 mod with a JAR not containing a mods.toml will not be allowed to be uploaded to Modrinth | ||
| - In project creation, projects may not upload a mod with no versions to review, however they can be saved as a draft | ||
| - Similarly, for version creation, a version may not be uploaded without any files | ||
| - Donation URLs have been enabled | ||
| - New project status: `archived`. Projects with this status do not appear in search | ||
| - Tags (such as categories, loaders) now have icons (SVGs) and specific project types attached | ||
| - Dependencies have been wiped and replaced with a new system | ||
| - Notifications now have a `type` field, such as `project_update` | ||
|
|
||
| Along with this, project subroutes (such as `/v2/project/{id}/version`) now allow the slug to be used as the ID. This is also the case with user routes. | ||
|
|
||
| </details><details><summary>Minotaur v1 to Minotaur v2</summary> | ||
|
|
||
| Minotaur 2.x introduced a few breaking changes to how your buildscript is formatted. | ||
|
|
||
| First, instead of registering your own `publishModrinth` task, Minotaur now automatically creates a `modrinth` task. As such, you can replace the `task publishModrinth(type: TaskModrinthUpload) {` line with just `modrinth {`. | ||
|
|
||
| To declare supported Minecraft versions and mod loaders, the `gameVersions` and `loaders` arrays must now be used. The syntax for these are pretty self-explanatory. | ||
|
|
||
| Instead of using `releaseType`, you must now use `versionType`. This was actually changed in v1.2.0, but very few buildscripts have moved on from v1.1.0. | ||
|
|
||
| Dependencies have been changed to a special DSL. Create a `dependencies` block within the `modrinth` block, and then use `scope.type("project/version")`. For example, `required.project("fabric-api")` adds a required project dependency on Fabric API. | ||
|
|
||
| You may now use the slug anywhere that a project ID was previously required. | ||
|
|
||
| </details> | ||
|
|
||
| <br /> | ||
|
|
||
| The above snippet about User Agents was adapted from https://crates.io/policies, copyright (c) 2014 The Rust Project Developers under MIT license. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minotaur not relevant