From f9d96a241e918a8ae2ee475905d65d3463b248df Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Sat, 17 Oct 2026 15:32:33 +0100 Subject: [PATCH] docs: refresh README --- README.md | 93 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 56 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index abc2f23..5bd2b2a 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,8 @@ # Appwrite PHP SDK -![License](https://img.shields.io/github/license/appwrite/sdk-for-php.svg?style=flat-square&v=1) +![License](https://img.shields.io/badge/license-BSD--3--Clause-blue.svg?style=flat-square) ![Version](https://img.shields.io/badge/api%20version-2.5.0-blue.svg?style=flat-square&v=1) -[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator) -[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite) +[![X Account](https://img.shields.io/badge/follow-%40appwrite-000000?logo=x&style=flat-square)](https://x.com/appwrite) [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord) **This SDK targets Appwrite server version 2.5.x as shipped on Appwrite Cloud.** Self-hosted releases can lag behind Cloud — if you run an older self-hosted build, use a matching older SDK from [previous releases](https://github.com/appwrite/sdk-for-php/releases) when APIs differ. @@ -14,7 +13,7 @@ Appwrite is an open-source backend as a service server that abstracts and simpli ## Installation -To install via [Composer](http://getcomposer.org/): +To install via [Composer](https://getcomposer.org/): ```bash composer require appwrite/appwrite @@ -49,76 +48,96 @@ $client->setEndpoint('https://cloud.appwrite.io/v1'); Configure timeouts, TLS, redirects, and connection reuse on the injected transport. The SDK's `setTimeout()`, `setConnectTimeout()`, and `setSelfSigned()` methods only configure the default cURL transport. Endpoint, authentication, headers, request encoding, and response handling remain the SDK's responsibility. A transport used with `responseType: 'location'` must have redirect following disabled. - ## Getting Started ### Init your SDK -Initialize your SDK with your Appwrite server API endpoint and project ID which can be found in your project settings page and your new API secret Key from project's API keys section. +Initialize the SDK with your Appwrite endpoint, project ID, and an API key. Find the endpoint and project ID in your project's **Settings** page, and create an API key with the scopes your code needs under **Overview > Integrations > API keys**. API keys grant server-level access, so keep them out of client-side code. ```php -$client = new Client(); - -$client - ->setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint - ->setProject('5df5acd0d48c2') // Your project ID - ->setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key - ->setSelfSigned() // Use only on dev mode with a self-signed SSL cert -; +use Appwrite\Client; + +$client = new Client() + ->setEndpoint('https://.cloud.appwrite.io/v1') + ->setProject('') + ->setKey(''); ``` -### Make Your First Request -Once your SDK object is set, create any of the Appwrite service objects and choose any request to send. Full documentation for any service method you would like to use can be found in your SDK documentation or in the [API References](https://appwrite.io/docs) section. +If you self-host Appwrite, use your own endpoint, such as `https://appwrite.example.com/v1`. During local development with a self-signed certificate, call `->setSelfSigned()` to skip certificate verification. Never use it in production. + +### Make your first request +Once the client is configured, create a service object and call any of its methods. Each method is documented in the [API references](https://appwrite.io/docs/references). ```php +use Appwrite\ID; +use Appwrite\Services\Users; + $users = new Users($client); -$user = $users->create(ID::unique(), "email@example.com", "+123456789", "password", "Walter O'Brien"); +$user = $users->create( + userId: ID::unique(), + email: 'email@example.com', + password: 'password', + name: "Walter O'Brien", +); + +echo $user->name; ``` -### Full Example +### Full example ```php +setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint - ->setProject('5df5acd0d48c2') // Your project ID - ->setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key - ->setSelfSigned() // Use only on dev mode with a self-signed SSL cert -; +$client = new Client() + ->setEndpoint('https://.cloud.appwrite.io/v1') + ->setProject('') + ->setKey(''); $users = new Users($client); -$user = $users->create(ID::unique(), "email@example.com", "+123456789", "password", "Walter O'Brien"); +$user = $users->create( + userId: ID::unique(), + email: 'email@example.com', + password: 'password', + name: "Walter O'Brien", +); + +echo $user->name; ``` -### Error Handling -The Appwrite PHP SDK raises `AppwriteException` object with `message`, `code` and `response` properties. You can handle any errors by catching `AppwriteException` and present the `message` to the user or handle it yourself based on the provided error information. Below is an example. +### Error handling +The SDK throws `Appwrite\AppwriteException` when a request fails. Use `getMessage()`, `getCode()`, `getType()`, and `getResponse()` to inspect the error. ```php -$users = new Users($client); +use Appwrite\AppwriteException; + try { - $user = $users->create(ID::unique(), "email@example.com", "+123456789", "password", "Walter O'Brien"); -} catch(AppwriteException $error) { + $user = $users->create( + userId: ID::unique(), + email: 'email@example.com', + password: 'password', + name: "Walter O'Brien", + ); +} catch (AppwriteException $error) { echo $error->getMessage(); } - ``` ### Learn more -You can use the following resources to learn more and get help -- 🚀 [Getting Started Tutorial](https://appwrite.io/docs/getting-started-for-server) +You can use the following resources to learn more and get help: +- 🚀 [PHP Quick Start](https://appwrite.io/docs/quick-starts/php) - 📜 [Appwrite Docs](https://appwrite.io/docs) - 💬 [Discord Community](https://appwrite.io/discord) - 🚂 [Appwrite PHP Playground](https://github.com/appwrite/playground-for-php) - ## Contribution -This library is auto-generated by Appwrite custom [SDK Generator](https://github.com/appwrite/sdk-generator). To learn more about how you can help us improve this SDK, please check the [contribution guide](https://github.com/appwrite/sdk-generator/blob/master/CONTRIBUTING.md) before sending a pull-request. +This library is auto-generated by Appwrite custom [SDK Generator](https://github.com/appwrite/sdk-generator). To learn more about how you can help us improve this SDK, please check the [contribution guide](https://github.com/appwrite/sdk-generator/blob/main/CONTRIBUTING.md) before sending a pull-request. ## License