Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

REST API improvements in docs #385

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions app/views/docs/rest.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<p>The REST API allows you to access your Appwrite server through HTTP requests without the needing an SDK. Each endpoint in the API represents a specific operation on a specific resource.</p>

<h2><a href="/docs/rest#headers" id="headers">Headers</a></h2>
<h2><a href="#headers" id="headers">Headers</a></h2>
<p>Appwrite's REST APIs expect certain headers to be included with each request:</p>

<table class="full text-size-small">
Expand Down Expand Up @@ -47,13 +47,13 @@
</tbody>
</table>

<h2><a href="/docs/rest#no-headers" id="no-headers">Using Appwrite Without Headers</a></h2>
<h2><a href="#no-headers" id="no-headers">Using Appwrite Without Headers</a></h2>
<p>Some use cases do not allow custom headers, such as embedding images from Appwrite in HTML. In these cases, you can provide the Appwrite project ID using the query parameter <code>project</code>.</p>
<div class="ide margin-bottom" data-lang="html" data-lang-label="HTML">
<pre class="line-numbers"><code class="prism language-html" data-prism><?php echo htmlentities('<img src="https://cloud.appwrite.io/v1/storage/buckets/[BUCKET_ID]/files/[FILE_ID]/preview?project=[PROJECT_ID]">'); ?></code></pre>
</div>

<h2><a href="/docs/rest#client-auth" id="client-auth">Client Authentication</a></h2>
<h2><a href="#client-auth" id="client-auth">Client Authentication</a></h2>
<p>You can create account sessions with POST requests to the <a href="/docs/client/account">Account API</a>. Sessions are persisted using secured cookies. You can learn more about session persistence in the <a href="/docs/authentication#persistence">Authentication Guide</a>.</p>
<p>The example below shows creating an account session with the <a href="/docs/client/account#accountCreateEmailSession">Create Account Session with Email</a> endpoint.</p>
<div class="ide margin-bottom" data-lang="http" data-lang-label="HTTP">
Expand Down Expand Up @@ -81,7 +81,7 @@ Content-Type: application/json
X-Appwrite-Project: [PROJECT_ID]</code></pre>
</div>

<h2><a href="/docs/rest#server-auth" id="server-auth">Server Authentication</a></h2>
<h2><a href="#server-auth" id="server-auth">Server Authentication</a></h2>
<p>Server integrations use API keys to authenticate and are typically used for backend applications.</p>
<p>Server APIs are authenticated with API keys instead of account sessions. Simply pass an <a href="/docs/keys">API key</a> in the <code>X-Appwrite-key: [API-KEY]</code> header with the appropriate scopes.</p>

Expand All @@ -92,7 +92,7 @@ X-Appwrite-Project: [PROJECT_ID]
X-Appwrite-Key: [API_KEY]</code></pre>
</div>

<h2><a href="/docs/rest#server-auth" id="server-auth">JWT Authentication</a></h2>
<h2><a href="#server-auth" id="server-auth">JWT Authentication</a></h2>
<p>JWT authentication is frequently used by server applications to act on behalf of a user. Users generate tokens using the <a href="/docs/client/account#accountCreateJWT">Create JWT</a> endpoint. When issuing requests authenticated with a JWT, Appwrite will treat the request like it is from the authenticated user.</p>

<div class="ide margin-bottom" data-lang="http" data-lang-label="HTTP">
Expand All @@ -102,7 +102,7 @@ X-Appwrite-Project: [PROJECT_ID]
X-Appwrite-JWT: [TOKEN]</code></pre>
</div>

<h2><a href="/docs/rest#file-handling" id="file-handling">File Handling</a></h2>
<h2><a href="#file-handling" id="file-handling">File Handling</a></h2>
<p>Appwrite implements resumable, chunked uploads for files larger than 5MB. Chunked uploads send files in chunks of 5MB to reduce memory footprint and increase resilience when handling large files. Appwrite SDKs will automatically handle chunked uploads, but it is possible to implement this with the REST API directly.</p>

<p>Upload endpoints in Appwrite, such as <a href="/docs/client/storage#storageCreateFile">Create File</a> and <a href="/docs/server/functions#functionsCreateDeployment">Create Deployment</a>, are different from other endpoints. These endpoints take multipart form data instead of JSON data. To implement chunked uploads, you will need to implement the following headers:</p>
Expand Down Expand Up @@ -208,7 +208,7 @@ read("user:627a958ded6424a98a9f")
------WebKitFormBoundarye0m6iNBQNHlzTpVM--</code></pre>
</div>

<h2><a href="/docs/rest#permissions" id="permissions">Permissions</a></h2>
<h2><a href="#permissions" id="permissions">Permissions</a></h2>

<p>Appwrite SDKs have helpers to generate permission strings, but when using Appwrite without SDKs, you'd need to create the strings yourself.</p>

Expand Down Expand Up @@ -294,17 +294,17 @@ read("user:627a958ded6424a98a9f")
</tbody>
</table>

<ul>
<p>
<li class="margin-bottom"><a href="/docs/permissions" rel="noopener"><i class="icon-angle-circled-right margin-start-negative-tiny margin-end-tiny"></i> Learn more about permissions</a></li>
</ul>
</p>

<h2><a href="/docs/rest#unique-id" id="unique-id">Unique ID</a></h2>
<h2><a href="#unique-id" id="unique-id">Unique ID</a></h2>

<p>
Appwrite's SDKs have a helper <code>ID.unique()</code> to generate unique IDs. When using Appwrite without an SDK, pass the string <code>"unique()"</code> into the ID parameter.
</p>

<h2><a href="/docs/rest#query" id="query">Query Methods</a></h2>
<h2><a href="#query" id="query">Query Methods</a></h2>

<p>
Appwrite's SDKs provide a <code>Query</code> class to generate query strings. When using Appwrite without an SDK, you can template your own strings with the format below.
Expand Down Expand Up @@ -403,13 +403,23 @@ Appwrite's SDKs provide a <code>Query</code> class to generate query strings. Wh
<h3>Best Practice</h3>
<p>When using greater than, greater than or equal to, less than, or less than or equal to, it is not recommended to pass in multiple values. While the API will accept multiple values and return results with <b>or logic</b>, it's best practice to pass in only one value for performance reasons.</p>
</div>
<h2><a href="#rate-limits" id="rate-limits">Rate Limits</a></h2>
<p>Appwrite's REST APIs are protected by the same rate limit policies, just like when using SDKs. Each API has a different rate limit, which is documented in the <b>References</b> section of each service in the Appwrite documentation.</p>

<p>
<li class="margin-bottom"><a href="https://appwrite.io/docs/rate-limits" target="_blank" rel="noopener"><i class="icon-angle-circled-right margin-start-negative-tiny margin-end-tiny"></i> Learn more about Rate Limits</a></li>
</p>

<h2><a href="#stateless" id="stateless">Stateless</a></h2>
<p>Appwrite's REST APIs are stateless. Each time you make a request, Appwrite receives all the information it needs to perform the action, regardless of what requests you make before and after that request.</p>

<p>Since each requests is stateless, they can be handled in any given order when sent concurrently, as long as they don't make conflicting changes to the same resource.</p>

<h2><a href="/docs/rest#specs" id="specs">OpenAPI and Swagger Specs</a></h2>
<h2><a href="#specs" id="specs">OpenAPI and Swagger Specs</a></h2>

<p>
Appwrite provides a full REST API specification in the OpenAPI 3 and Swagger 2 formats every release. These can be accessed through Appwrite's GitHub repository and rendered using a variety of parsers and tools.
</p>
<ul>
<p>
<li class="margin-bottom"><a href="https://github.com/appwrite/appwrite/tree/master/app/config/specs" target="_blank" rel="noopener"><i class="icon-angle-circled-right margin-start-negative-tiny margin-end-tiny"></i> Find the REST API specification for your Appwrite version</a></li>
</ul>
</p>