### Start Local Supabase Instance Source: https://github.com/supabase/supabase-swift/blob/main/Examples/README.md Command to start a local Supabase instance from the /supabase directory. Ensure the Supabase CLI is installed. ```bash supabase start ``` -------------------------------- ### Start Supabase Local Development Source: https://github.com/supabase/supabase-swift/blob/main/Examples/README.md Run this command in the project's root directory to start local Supabase services. It makes the API, Studio, and Inbucket available at specified local addresses. ```bash cd /path/to/supabase-swift supabase start ``` -------------------------------- ### Invoke Hello World Function Source: https://github.com/supabase/supabase-swift/blob/main/Tests/FunctionsTests/__Snapshots__/RequestTests/testInvokeWithBody.1.txt Example of how to invoke the 'hello-world' function with a JSON payload. ```APIDOC ## POST /functions/v1/hello-world ### Description Invokes the 'hello-world' function with a JSON payload. ### Method POST ### Endpoint http://localhost:5432/functions/v1/hello-world ### Headers - **Content-Type**: application/json - **apikey**: supabase.publishable.key - **x-client-info**: functions-swift/x.y.z ### Request Body - **name** (string) - Required - The name to be used in the function. ### Request Example { "name": "Supabase" } ### Response #### Success Response (200) (Response structure not provided in source) ``` -------------------------------- ### Initialize Supabase Client Source: https://github.com/supabase/supabase-swift/blob/main/README.md Initialize the Supabase client with your Supabase URL and publishable API key. This is the basic setup required to interact with Supabase services. ```swift let client = SupabaseClient( supabaseURL: URL(string: "https://xyzcompany.supabase.co")!, supabaseKey: "your-publishable-key" ) ``` -------------------------------- ### GET /users Source: https://github.com/supabase/supabase-swift/blob/main/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.test-contains-filter-with-array.txt Retrieves a list of users from the Supabase database with optional filtering and selection parameters. ```APIDOC ## GET /users ### Description Retrieves user records from the database. Supports filtering via query parameters and field selection. ### Method GET ### Endpoint https://example.supabase.co/users ### Parameters #### Query Parameters - **name** (string) - Optional - Filter users by attributes (e.g., cs.{is:online,faction:red}) - **select** (string) - Optional - Comma-separated list of columns to return ### Request Example curl --header "Accept: application/json" "https://example.supabase.co/users?name=cs.%7Bis:online,faction:red%7D&select=*" ### Response #### Success Response (200) - **data** (array) - List of user objects matching the criteria #### Response Example [ { "id": 1, "name": "user_name", "status": "online", "faction": "red" } ] ``` -------------------------------- ### Create Todo Item Source: https://github.com/supabase/supabase-swift/blob/main/Examples/README.md Example of creating a new todo item in the 'todos' table. Ensure the 'Todo' model is defined and the Supabase client is initialized. ```swift CodeExample( code: """ // Create a todo try await supabase .from(\"todos\") .insert(Todo(description: \"Learn Supabase\")) .execute() """ ) ``` -------------------------------- ### Format Swift Code Source: https://github.com/supabase/supabase-swift/blob/main/README.md Run this command to format Swift code according to project standards. Ensure you have the 'make' utility installed. ```bash make format ``` -------------------------------- ### Swift Test Structure Example Source: https://github.com/supabase/supabase-swift/blob/main/AGENTS.md Example structure for a unit test class using XCTest in Swift, demonstrating Arrange-Act-Assert pattern. ```swift import XCTest @testable import ModuleName final class FeatureTests: XCTestCase { func testFeatureBehavior() { // Arrange let input = "test" // Act let result = feature(input) // Assert XCTAssertEqual(result, expected) } } ``` -------------------------------- ### GET /users Source: https://github.com/supabase/supabase-swift/blob/main/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.likeAnyOf.txt Retrieves a list of users from the Supabase database based on specific email filtering criteria. ```APIDOC ## GET /users ### Description Retrieves user records from the database that match the provided email pattern using PostgREST filtering. ### Method GET ### Endpoint https://example.supabase.co/users ### Parameters #### Query Parameters - **email** (string) - Required - Filter users by email pattern using like(any) operator. - **select** (string) - Optional - Specifies which columns to return (e.g., * for all). ### Request Example curl -X GET "https://example.supabase.co/users?email=like(any).%7B%25@supabase.io,%25@supabase.com%7D&select=*" ### Response #### Success Response (200) - **data** (array) - List of user objects matching the criteria. #### Response Example [ { "id": "uuid", "email": "user@supabase.io" } ] ``` -------------------------------- ### GET /objects Source: https://github.com/supabase/supabase-swift/blob/main/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.query-non-default-schema.txt Retrieves a list of all objects from the storage bucket. This example demonstrates fetching all objects with their details. ```APIDOC ## GET /objects ### Description Retrieves a list of all objects from the storage bucket. This example demonstrates fetching all objects with their details. ### Method GET ### Endpoint /objects?select=* ### Parameters #### Query Parameters - **select** (string) - Required - Specifies the columns to retrieve. `*` retrieves all columns. ### Request Example ```bash curl \ --header "Accept: application/json" \ --header "Accept-Profile: storage" \ --header "Content-Type: application/json" \ --header "X-Client-Info: postgrest-swift/x.y.z" \ "https://example.supabase.co/objects?select=*" ``` ### Response #### Success Response (200) - **id** (uuid) - The unique identifier of the object. - **name** (string) - The name of the object. - **bucket_id** (uuid) - The ID of the bucket the object belongs to. - **owner** (uuid) - The ID of the user who owns the object. - **created_at** (timestamp) - The timestamp when the object was created. - **updated_at** (timestamp) - The timestamp when the object was last updated. - **last_accessed_at** (timestamp) - The timestamp when the object was last accessed. #### Response Example ```json [ { "id": "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", "name": "example.jpg", "bucket_id": "f47ac10b-58cc-4372-a567-0e02b2c3d479", "owner": "a1b2c3d4-e5f6-7890-1234-567890abcdef", "created_at": "2023-10-27T10:00:00Z", "updated_at": "2023-10-27T10:00:00Z", "last_accessed_at": "2023-10-27T10:00:00Z" } ] ``` ``` -------------------------------- ### POST /users Source: https://github.com/supabase/supabase-swift/blob/main/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.bulk-insert-users.txt Inserts one or more user records into the database using the Supabase REST API. ```APIDOC ## POST /users ### Description Inserts new user records into the users table. Supports bulk insertion by providing an array of objects. ### Method POST ### Endpoint https://example.supabase.co/users ### Parameters #### Query Parameters - **columns** (string) - Optional - Comma-separated list of columns to return in the response. #### Request Body - **Array of Objects** (json) - Required - A list of user objects containing fields like email and username. ### Request Example [ {"email":"johndoe@supabase.io"}, {"email":"johndoe2@supabase.io","username":"johndoe2"} ] ### Response #### Success Response (200) - **data** (array) - The list of inserted user records. #### Response Example [ {"id": 1, "email": "johndoe@supabase.io", "username": null}, {"id": 2, "email": "johndoe2@supabase.io", "username": "johndoe2"} ] ``` -------------------------------- ### RPC Example: Sum Function Source: https://github.com/supabase/supabase-swift/blob/main/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.rpc-call-with-get.txt This snippet demonstrates how to call a remote procedure call (RPC) function named 'sum' on Supabase using the Swift client. It includes the necessary headers and the endpoint URL. ```APIDOC ## POST /rpc/sum ### Description This endpoint allows you to call the 'sum' remote procedure call (RPC) function provided by Supabase. It's typically used for custom database functions. ### Method POST ### Endpoint /rpc/sum ### Parameters #### Query Parameters None #### Request Body This endpoint expects a JSON body, typically containing arguments for the 'sum' function. The exact structure depends on the function definition in your Supabase project. ### Request Example ```json { "a": 10, "b": 5 } ``` ### Response #### Success Response (200) - **result** (number) - The result returned by the 'sum' RPC function. #### Response Example ```json { "result": 15 } ``` ``` -------------------------------- ### POST /users Source: https://github.com/supabase/supabase-swift/blob/main/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.test-upsert-not-ignoring-duplicates.txt This endpoint is used to create a new user, typically for registration purposes. It requires an email address in the request body. ```APIDOC ## POST /users ### Description Creates a new user with the provided email address. ### Method POST ### Endpoint /users ### Parameters #### Query Parameters None #### Request Body - **email** (string) - Required - The email address of the user to create. ### Request Example ```json { "email": "johndoe@supabase.io" } ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the newly created user. - **email** (string) - The email address of the user. #### Response Example ```json { "id": "a1b2c3d4-e5f6-7890-1234-567890abcdef", "email": "johndoe@supabase.io" } ``` ``` -------------------------------- ### Listen for Postgres Insertions in Swift Source: https://github.com/supabase/supabase-swift/blob/main/docs/migrations/RealtimeV2 Migration Guide.md Listen for new record insertions in a specified table using RealtimeV2's `postgresChange` method. This example decodes the inserted record into a `Message` object. ```swift let channel = await supabase.realtimeV2.channel("public:messages") for await insertion in channel.postgresChange(InsertAction.self, table: "messages") { let insertedMessage = try insertion.decodeRecord(as: Message.self) } ``` -------------------------------- ### Listen for Postgres Updates in Swift Source: https://github.com/supabase/supabase-swift/blob/main/docs/migrations/RealtimeV2 Migration Guide.md Listen for record updates in a specified table using RealtimeV2's `postgresChange` method. This example decodes both the updated record and the old record into `Message` objects. ```swift let channel = await supabase.realtimeV2.channel("public:messages") for await update in channel.postgresChange(UpdateAction.self, table: "messages") { let updateMessage = try update.decodeRecord(as: Message.self) let oldMessage = try update.decodeOldRecord(as: Message.self) } ``` -------------------------------- ### Query Users by Email (NULL) Source: https://github.com/supabase/supabase-swift/blob/main/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.query-if-nil-value.txt Example of how to query users where the email is NULL using the Supabase API. Ensure correct headers are set for authentication and content type. ```bash curl \ --header "Accept: application/json" \ --header "Content-Type: application/json" \ --header "X-Client-Info: postgrest-swift/x.y.z" \ "https://example.supabase.co/users?email=is.NULL&select=*" ``` -------------------------------- ### Swift File Header Example Source: https://github.com/supabase/supabase-swift/blob/main/AGENTS.md Standard file header format for Swift files in the Supabase project, including filename, module name, and creation date. ```swift // // FileName.swift // ModuleName // // Created by Author Name on DD/MM/YY. // ``` -------------------------------- ### Make Supabase API Request with Curl Source: https://github.com/supabase/supabase-swift/blob/main/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.test-contains-filter-with-array.txt This snippet demonstrates how to make a GET request to the Supabase API using curl. It includes essential headers like 'Accept', 'Content-Type', and 'X-Client-Info', along with a query parameter for filtering users by name and online status. The 'select=*' clause retrieves all columns. ```bash curl \ --header "Accept: application/json" \ --header "Content-Type: application/json" \ --header "X-Client-Info: postgrest-swift/x.y.z" \ "https://example.supabase.co/users?name=cs.%7Bis:online,faction:red%7D&select=*" ``` -------------------------------- ### Run Integration Tests with Local Supabase Instance Source: https://github.com/supabase/supabase-swift/blob/main/AGENTS.md Provides a bash script to set up and run integration tests. This involves starting a local Supabase instance, resetting the database, running tests, and then stopping the instance. ```bash cd Tests/IntegrationTests supabase start supabase db reset cd ../.. swift test --filter IntegrationTests cd Tests/IntegrationTests supabase stop ``` -------------------------------- ### Signup User with Supabase Auth (cURL) Source: https://github.com/supabase/supabase-swift/blob/main/Tests/AuthTests/__Snapshots__/RequestsTests/testSignUpWithEmailAndPassword.1.txt This snippet shows how to sign up a new user using the Supabase Auth GoTrue API via a cURL command. It includes essential headers like API key, content type, client info, and API version, along with a JSON data payload containing user credentials and optional metadata. The `redirect_to` parameter specifies the URL for email confirmation. ```shell curl \ --request POST \ --header "Apikey: dummy.api.key" \ --header "Content-Type: application/json" \ --header "X-Client-Info: gotrue-swift/x.y.z" \ --header "X-Supabase-Api-Version: 2024-01-01" \ --data "{\"data\":{\"custom_key\":\"custom_value\"},\"email\":\"example@mail.com\",\"gotrue_meta_security\":{\"captcha_token\":\"dummy-captcha\"},\"password\":\"the.pass\"}" \ "http://localhost:54321/auth/v1/signup?redirect_to=https://supabase.com" ``` -------------------------------- ### Fetch Tasks with Filtering and Ordering Source: https://github.com/supabase/supabase-swift/blob/main/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.query-with-timestampz.txt Example of fetching tasks from Supabase with specific filtering and ordering parameters using a curl command. Ensure the 'X-Client-Info' header is updated with your client version. ```curl curl \ --header "Accept: application/json" \ --header "Content-Type: application/json" \ --header "X-Client-Info: postgrest-swift/x.y.z" \ "https://example.supabase.co/tasks?order=received_at.asc.nullslast&received_at=gt.2023-03-23T15:50:30.511743+00:00&select=*" ``` -------------------------------- ### Restart Supabase Services Source: https://github.com/supabase/supabase-swift/blob/main/Examples/README.md Use `supabase stop` followed by `supabase start` to restart your local Supabase services. This can resolve issues caused by services not responding correctly. ```bash # Restart services supabase stop supabase start ``` -------------------------------- ### POST /auth/v1/token Source: https://github.com/supabase/supabase-swift/blob/main/Tests/AuthTests/__Snapshots__/RequestsTests/testSignInWithEmailAndPassword.1.txt Authenticates a user using their email and password and returns a session token. Includes optional security meta-data. ```APIDOC ## POST /auth/v1/token ### Description Authenticates a user by email and password, returning a session token. Supports optional security meta-data like captcha tokens. ### Method POST ### Endpoint http://localhost:54321/auth/v1/token?grant_type=password ### Parameters #### Query Parameters - **grant_type** (string) - Required - Specifies the grant type, expected to be 'password' for this endpoint. #### Headers - **Apikey** (string) - Required - Your Supabase API key. - **Content-Type** (string) - Required - Must be 'application/json'. - **X-Client-Info** (string) - Optional - Information about the client, e.g., 'gotrue-swift/x.y.z'. - **X-Supabase-Api-Version** (string) - Optional - The API version, e.g., '2024-01-01'. #### Request Body - **email** (string) - Required - The user's email address. - **password** (string) - Required - The user's password. - **gotrue_meta_security** (object) - Optional - Security meta-data. - **captcha_token** (string) - Required if `gotrue_meta_security` is present - The token obtained from a CAPTCHA service. ### Request Example ```json { "email": "example@mail.com", "gotrue_meta_security": { "captcha_token": "dummy-captcha" }, "password": "the.pass" } ``` ### Response #### Success Response (200) - **access_token** (string) - The JWT access token for the authenticated user. - **refresh_token** (string) - The refresh token for obtaining new access tokens. - **user** (object) - User details. - **id** (string) - User's unique identifier. - **aud** (string) - Audience claim for the token. - **role** (string) - User's role. - **email** (string) - User's email address. - **confirmed_at** (string) - Timestamp when the email was confirmed. - **created_at** (string) - Timestamp when the user was created. - **updated_at** (string) - Timestamp when the user was last updated. #### Response Example ```json { "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "refresh_token": "...", "user": { "id": "d290f1ee-8c7c-4b2f-931e-561c1900d0b8", "aud": "authenticated", "role": "authenticated", "email": "example@mail.com", "confirmed_at": "2024-01-01T12:00:00.000Z", "created_at": "2024-01-01T11:00:00.000Z", "updated_at": "2024-01-01T11:00:00.000Z" } } ``` ``` -------------------------------- ### Fetch User Data with Curl Source: https://github.com/supabase/supabase-swift/blob/main/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.query-with-character.txt This snippet demonstrates how to fetch user data from a Supabase instance using a curl command. It includes essential headers like 'Accept', 'Content-Type', and 'X-Client-Info', along with a query parameter to filter users by ID. Ensure you replace 'example.supabase.co' with your actual Supabase project URL. ```shell curl \ --header "Accept: application/json" \ --header "Content-Type: application/json" \ --header "X-Client-Info: postgrest-swift/x.y.z" \ "https://example.supabase.co/users?id=eq.Cig%C3%A1nyka-%C3%A9r%20(0+400%20cskm)%20v%C3%ADzrajzi%20%C3%A1llom%C3%A1s&select=*" ``` -------------------------------- ### Create User via cURL Source: https://github.com/supabase/supabase-swift/blob/main/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.test-upsert-not-ignoring-duplicates.txt This cURL command demonstrates how to create a new user in Supabase. It specifies the HTTP method, required headers for content negotiation and client identification, and the JSON payload containing the user's email. The 'Prefer' header is used to control the API's response. ```bash curl \ --request POST \ --header "Accept: application/json" \ --header "Content-Type: application/json" \ --header "Prefer: resolution=merge-duplicates,return=representation" \ --header "X-Client-Info: postgrest-swift/x.y.z" \ --data "{\"email\":\"johndoe@supabase.io\"}" \ "https://example.supabase.co/users" ``` -------------------------------- ### Invoke Function with Custom Method Source: https://github.com/supabase/supabase-swift/blob/main/Tests/FunctionsTests/__Snapshots__/RequestTests/testInvokeWithCustomMethod.1.txt This example demonstrates how to invoke a Supabase Function using a custom HTTP method like PATCH. ```APIDOC ## PATCH /functions/v1/hello-world ### Description Invokes the 'hello-world' function using the PATCH HTTP method. ### Method PATCH ### Endpoint /functions/v1/hello-world ### Headers - **apikey**: supabase.publishable.key - **x-client-info**: functions-swift/x.y.z ### Request Example ```bash curl \ --request PATCH \ --header "apikey: supabase.publishable.key" \ --header "x-client-info: functions-swift/x.y.z" \ "http://localhost:5432/functions/v1/hello-world" ``` ``` -------------------------------- ### Make RPC Call with cURL Source: https://github.com/supabase/supabase-swift/blob/main/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.call-rpc-with-filter.txt Example of how to make a Remote Procedure Call (RPC) to Supabase using cURL. Ensure the correct headers and URL are used. ```bash curl \ --request POST \ --header "Accept: application/json" \ --header "Content-Type: application/json" \ --header "X-Client-Info: postgrest-swift/x.y.z" \ "https://example.supabase.co/rpc/test_fcn?id=eq.1" ``` -------------------------------- ### Invoke Function with Custom Header Source: https://github.com/supabase/supabase-swift/blob/main/Tests/FunctionsTests/__Snapshots__/RequestTests/testInvokeWithCustomHeader.1.txt This example demonstrates how to invoke a Supabase Function using a POST request and includes custom headers like 'apikey', 'x-client-info', and 'x-custom-key'. ```APIDOC ## POST /functions/v1/hello-world ### Description Invokes the 'hello-world' Supabase Function with custom headers. ### Method POST ### Endpoint http://localhost:5432/functions/v1/hello-world ### Headers - **apikey** (string) - Required - Supabase publishable key. - **x-client-info** (string) - Required - Client information, typically including the SDK name and version. - **x-custom-key** (string) - Optional - A custom header for specific use cases. ### Request Example ```bash curl \ --request POST \ --header "apikey: supabase.publishable.key" \ --header "x-client-info: functions-swift/x.y.z" \ --header "x-custom-key: custom value" \ "http://localhost:5432/functions/v1/hello-world" ``` ``` -------------------------------- ### GET /todos Source: https://github.com/supabase/supabase-swift/blob/main/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.test-all-filters-and-count.txt Retrieves a list of todo items from the Supabase backend. Supports filtering by various column operators. ```APIDOC ## GET /todos ### Description Retrieves a list of todo items. This endpoint allows for extensive filtering based on column values using various operators. ### Method GET ### Endpoint /todos ### Query Parameters - **column** (string) - Optional - Allows filtering based on column values. Supports operators like eq, neq, gt, gte, lt, lte, like, ilike, match, imatch, is, isdistinct, in, cs, cd, sl, sr, nxl, nxr, adj, ov, fts, plfts, phfts, wfts. - **select** (string) - Optional - Specifies which columns to return. Use `*` to select all columns. ### Request Example ```bash curl \ --header "Accept: application/json" \ --header "Content-Type: application/json" \ --header "X-Client-Info: postgrest-swift/x.y.z" \ "https://example.supabase.co/todos?column=eq.Some%20value&column=neq.Some%20value&column=gt.Some%20value&column=gte.Some%20value&column=lt.Some%20value&column=lte.Some%20value&column=like.Some%20value&column=ilike.Some%20value&column=match.Some%20value&column=imatch.Some%20value&column=is.Some%20value&column=isdistinct.Some%20value&column=in.Some%20value&column=cs.Some%20value&column=cd.Some%20value&column=sl.Some%20value&column=sr.Some%20value&column=nxl.Some%20value&column=nxr.Some%20value&column=adj.Some%20value&column=ov.Some%20value&column=fts.Some%20value&column=plfts.Some%20value&column=phfts.Some%20value&column=wfts.Some%20value&select=*" ``` ### Response #### Success Response (200) - **Array of Todo Objects** (object[]) - A list of todo items matching the query criteria. #### Response Example ```json { "example": "[{"id": 1, "title": "Learn Supabase", "is_complete": false}]" } ``` ``` -------------------------------- ### Fetch All Users with Metadata Filter (curl) Source: https://github.com/supabase/supabase-swift/blob/main/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.containedBy-using-json.txt This snippet demonstrates how to fetch all users from a Supabase instance using curl. It includes headers for content type and client information, and a query parameter to filter users based on their metadata, specifically selecting users with an age of 18 or older. Ensure you replace 'example.supabase.co' with your actual Supabase project URL. ```shell curl \ --header "Accept: application/json" \ --header "Content-Type: application/json" \ --header "X-Client-Info: postgrest-swift/x.y.z" \ "https://example.supabase.co/users?select=*&userMetadata=cd.%7B%22age%22:18%7D" ``` -------------------------------- ### Reset Supabase Database Source: https://github.com/supabase/supabase-swift/blob/main/Examples/README.md Use this command to reset the local Supabase database and load seed data. This is useful for starting with a clean slate or testing data seeding. ```bash supabase db reset ``` -------------------------------- ### Create Users via Supabase API (curl) Source: https://github.com/supabase/supabase-swift/blob/main/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.bulk-insert-users.txt This snippet demonstrates how to create multiple users in Supabase using a curl command. It specifies the request method, headers for content type and client information, and a JSON data payload containing user email and optional username. The target URL points to the Supabase API endpoint for users. ```shell curl \ --request POST \ --header "Accept: application/json" \ --header "Content-Type: application/json" \ --header "X-Client-Info: postgrest-swift/x.y.z" \ --data "[{"email":"johndoe@supabase.io"},{"email":"johndoe2@supabase.io","username":"johndoe2"}]" \ "https://example.supabase.co/users?columns=email,username" ``` -------------------------------- ### Fetch All Users with Filter via Curl Source: https://github.com/supabase/supabase-swift/blob/main/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.filter-starting-with-non-alphanumeric.txt This snippet demonstrates fetching all users from a Supabase API endpoint using curl. It includes essential headers for API interaction and a query parameter to filter results. ```shell curl \ --header "Accept: application/json" \ --header "Content-Type: application/json" \ --header "X-Client-Info: postgrest-swift/x.y.z" \ "https://example.supabase.co/users?select=*&to=eq.+16505555555" ``` -------------------------------- ### Fetch Users with Email Filter via Curl Source: https://github.com/supabase/supabase-swift/blob/main/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.likeAnyOf.txt This snippet demonstrates how to fetch user data from Supabase using a curl command. It includes headers for content type and client information, and filters users by email patterns while selecting all columns. This is useful for direct API interaction without a client library. ```shell curl \ --header "Accept: application/json" \ --header "Content-Type: application/json" \ --header "X-Client-Info: postgrest-swift/x.y.z" \ "https://example.supabase.co/users?email=like(any).%7B%25@supabase.io,%25@supabase.com%7D&select=*" ``` -------------------------------- ### Query Users with JSON Filter Source: https://github.com/supabase/supabase-swift/blob/main/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.test-contains-filter-with-dictionary.txt Example of a cURL request to query users with a JSON filter on their address. Ensure the X-Client-Info header is set correctly for your PostgREST version. ```curl curl \ --header "Accept: application/json" \ --header "Content-Type: application/json" \ --header "X-Client-Info: postgrest-swift/x.y.z" \ "https://example.supabase.co/users?address=cs.%7B%22postcode%22:90210%7D&select=name" ``` -------------------------------- ### Make RPC Call with Curl Source: https://github.com/supabase/supabase-swift/blob/main/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.call-rpc-without-parameter.txt Example of how to make a Remote Procedure Call (RPC) to a Supabase backend using curl. Ensure to replace 'example.supabase.co' with your actual Supabase project URL and 'test_fcn' with your function name. ```bash curl \ --request POST \ --header "Accept: application/json" \ --header "Content-Type: application/json" \ --header "X-Client-Info: postgrest-swift/x.y.z" \ "https://example.supabase.co/rpc/test_fcn" ``` -------------------------------- ### Invoke Function with Custom Region Source: https://github.com/supabase/supabase-swift/blob/main/Tests/FunctionsTests/__Snapshots__/RequestTests/testInvokeWithCustomRegion.1.txt This example shows how to invoke a Supabase Function using a POST request, specifying a custom region through both the `x-region` header and the `forceFunctionRegion` query parameter. ```APIDOC ## POST /functions/v1/hello-world ### Description Invokes the 'hello-world' function in a specified custom region. ### Method POST ### Endpoint http://localhost:5432/functions/v1/hello-world?forceFunctionRegion=ap-northeast-1 ### Headers - **apikey** (string) - Required - Your Supabase publishable API key. - **x-client-info** (string) - Required - Client information, e.g., `functions-swift/x.y.z`. - **x-region** (string) - Required - The custom region to invoke the function in, e.g., `ap-northeast-1`. ### Query Parameters - **forceFunctionRegion** (string) - Required - Specifies the region for the function invocation, e.g., `ap-northeast-1`. ### Request Example ```bash curl \ --request POST \ --header "apikey: supabase.publishable.key" \ --header "x-client-info: functions-swift/x.y.z" \ --header "x-region: ap-northeast-1" \ "http://localhost:5432/functions/v1/hello-world?forceFunctionRegion=ap-northeast-1" ``` ``` -------------------------------- ### Track User Presence with Codable in Swift Source: https://github.com/supabase/supabase-swift/blob/main/docs/migrations/RealtimeV2 Migration Guide.md Track user presence in a RealtimeV2 channel using a `Codable` struct for more complex presence data. This allows for structured data to be sent with presence updates. ```swift struct UserPresence: Codable { let userId: String } await channel.track(UserPresence(userId: "abc_123")) ``` -------------------------------- ### Track User Presence with Dictionary in Swift Source: https://github.com/supabase/supabase-swift/blob/main/docs/migrations/RealtimeV2 Migration Guide.md Track user presence in a RealtimeV2 channel using a dictionary to represent the presence state. This is useful for simple presence data like a user ID. ```swift let channel = await supabase.realtimeV2.channel("room") await channel.track(state: ["user_id": "abc_123"]) ``` -------------------------------- ### Call Supabase RPC with Curl Source: https://github.com/supabase/supabase-swift/blob/main/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.rpc-call-with-get.txt This snippet shows how to invoke a Supabase Remote Procedure Call (RPC) using the curl command-line tool. It includes essential headers for authentication and content type, targeting a specific RPC endpoint. ```bash curl \ --header "Accept: application/json" \ --header "Content-Type: application/json" \ --header "X-Client-Info: postgrest-swift/x.y.z" \ "https://example.supabase.co/rpc/sum" ``` -------------------------------- ### Listen for All Postgres Changes in Swift Source: https://github.com/supabase/supabase-swift/blob/main/docs/migrations/RealtimeV2 Migration Guide.md Listen for any type of Postgres change (insert, update, delete) in a specified table using RealtimeV2's `postgresChange` method with `AnyAction.self`. The change enum provides access to different action types. ```swift let channel = await supabase.realtimeV2.channel("public:messages") for change in channel.postgresChange(AnyAction.self, table: "messages") { // change: enum with insert, update, and delete cases. } ``` -------------------------------- ### Initialize Supabase Client with Custom Options Source: https://github.com/supabase/supabase-swift/blob/main/README.md Initialize the Supabase client with custom options for database schema, authentication storage and flow, and global headers or session. This allows for more advanced configurations. ```swift let client = SupabaseClient( supabaseURL: URL(string: "https://xyzcompany.supabase.co")!, supabaseKey: "your-publishable-key", options: SupabaseClientOptions( db: .init( schema: "public" ), auth: .init( storage: MyCustomLocalStorage(), flowType: .pkce ), global: .init( headers: ["x-my-custom-header": "my-app-name"], session: URLSession.myCustomSession ) ) ) ``` -------------------------------- ### Listen for Postgres Deletions in Swift Source: https://github.com/supabase/supabase-swift/blob/main/docs/migrations/RealtimeV2 Migration Guide.md Listen for record deletions in a specified table using RealtimeV2's `postgresChange` method. This example decodes the old record to extract the ID of the deleted record. ```swift let channel = await supabase.realtimeV2.channel("public:messages") for await deletion in channel.postgresChange(DeleteAction.self, table: "messages") { struct Payload: Decodable { let id: UUID } let payload = try deletion.decodeOldRecord(as: Payload.self) let deletedMessageID = payload.id } ``` -------------------------------- ### Configure Supabase Client with Options Builder Source: https://github.com/supabase/supabase-swift/blob/main/AGENTS.md Demonstrates how to initialize the Supabase client using the option builder pattern. This allows for granular configuration of authentication, database, and global settings. ```swift SupabaseClient( supabaseURL: url, supabaseKey: key, options: SupabaseClientOptions( auth: .init(...), db: .init(...), global: .init(...) ) ) ``` -------------------------------- ### User Signup API Source: https://github.com/supabase/supabase-swift/blob/main/Tests/AuthTests/__Snapshots__/RequestsTests/testSignInAnonymously.1.txt Allows new users to sign up for an account using email and password, with optional metadata and security tokens. ```APIDOC ## POST /auth/v1/signup ### Description This endpoint facilitates the creation of a new user account within the Supabase authentication system. It supports sending custom data and security tokens like captcha tokens. ### Method POST ### Endpoint /auth/v1/signup ### Parameters #### Headers - **Apikey** (string) - Required - Your Supabase API key. - **Content-Type** (string) - Required - Must be `application/json`. - **X-Client-Info** (string) - Optional - Information about the client, e.g., `gotrue-swift/x.y.z`. - **X-Supabase-Api-Version** (string) - Optional - Specifies the API version, e.g., `2024-01-01`. #### Request Body - **data** (object) - Optional - An object containing custom key-value pairs for user data. - **custom_key** (string) - Example custom field. - **gotrue_meta_security** (object) - Optional - Security-related metadata. - **captcha_token** (string) - Required if security measures are enabled - The token obtained from a CAPTCHA challenge. ### Request Example ```json { "data": { "custom_key": "custom_value" }, "gotrue_meta_security": { "captcha_token": "captcha-token" } } ``` ### Response #### Success Response (200) - **id** (uuid) - The unique identifier for the newly created user. - **aud** (string) - The audience associated with the user token. - **role** (string) - The default role assigned to the user. - **email** (string) - The email address of the user. - **created_at** (timestamp) - The timestamp when the user account was created. - **user_metadata** (object) - Any metadata associated with the user. #### Response Example ```json { "id": "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", "aud": "authenticated", "role": "authenticated", "email": "user@example.com", "created_at": "2024-01-20T10:00:00Z", "user_metadata": { "custom_key": "custom_value" } } ``` ``` -------------------------------- ### GET /users Source: https://github.com/supabase/supabase-swift/blob/main/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.query-if-nil-value.txt Retrieves user data from the Supabase backend. ```APIDOC ## GET /users ### Description Retrieves user data from the Supabase backend, allowing filtering by email and selection of specific fields. ### Method GET ### Endpoint https://example.supabase.co/users ### Query Parameters - **email** (string) - Optional - Filters users where the email is NULL. - **select** (string) - Optional - Specifies which columns to return. '*' selects all columns. ### Request Example ```bash curl \ --header "Accept: application/json" \ --header "Content-Type: application/json" \ --header "X-Client-Info: postgrest-swift/x.y.z" \ "https://example.supabase.co/users?email=is.NULL&select=*" ``` ### Response #### Success Response (200) - **Array of user objects** (object[]) - Contains the user data matching the query. #### Response Example ```json [ { "id": "123e4567-e89b-12d3-a456-426614174000", "email": "user@example.com", "created_at": "2023-01-01T12:00:00Z" } ] ``` ``` -------------------------------- ### GET /users Source: https://github.com/supabase/supabase-swift/blob/main/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.test-contains-filter-with-dictionary.txt Retrieves user data from the Supabase API with filtering and selection. ```APIDOC ## GET /users ### Description Retrieves user data from the Supabase API, allowing for filtering by address and selecting specific fields. ### Method GET ### Endpoint https://example.supabase.co/users ### Query Parameters - **address** (string) - Required - Filters users based on address. The value is a JSON string representing an address object, e.g., `{"postcode":90210}`. - **select** (string) - Required - Specifies which fields to return, e.g., `name`. ### Request Example ```bash curl \ --header "Accept: application/json" \ --header "Content-Type: application/json" \ --header "X-Client-Info: postgrest-swift/x.y.z" \ "https://example.supabase.co/users?address=cs.%7B%22postcode%22:90210%7D&select=name" ``` ### Response #### Success Response (200) - **name** (string) - The name of the user. #### Response Example ```json { "name": "John Doe" } ``` ``` -------------------------------- ### GET /users Source: https://github.com/supabase/supabase-swift/blob/main/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.containedBy-using-array.txt Retrieves user records from the Supabase database with specific filtering criteria. ```APIDOC ## GET /users ### Description Retrieves a list of users from the database based on provided query parameters. ### Method GET ### Endpoint https://example.supabase.co/users ### Parameters #### Query Parameters - **id** (string) - Optional - Filter users by ID using comma-separated values (e.g., cd.{a,b,c}) - **select** (string) - Optional - Specifies which columns to return (e.g., * for all columns) ### Request Example curl --header "Accept: application/json" --header "Content-Type: application/json" --header "X-Client-Info: postgrest-swift/x.y.z" "https://example.supabase.co/users?id=cd.%7Ba,b,c%7D&select=*" ``` -------------------------------- ### Invoke Hello World Function Source: https://github.com/supabase/supabase-swift/blob/main/Tests/FunctionsTests/__Snapshots__/RequestTests/testInvokeWithDefaultOptions.1.txt This snippet shows how to invoke the 'hello-world' function using a POST request. ```APIDOC ## POST /functions/v1/hello-world ### Description Invokes the 'hello-world' serverless function. ### Method POST ### Endpoint http://localhost:5432/functions/v1/hello-world ### Headers - **apikey** (string) - Required - Your Supabase publishable API key. - **x-client-info** (string) - Required - Client information, typically including the SDK name and version. ### Request Example ```json { "example": "This is a sample request body, if required by the function." } ``` ### Response #### Success Response (200) - **body** (any) - The response from the invoked function. #### Response Example ```json { "message": "Hello from Supabase!" } ``` ``` -------------------------------- ### Initialize Database Schema and Storage for Supabase Source: https://github.com/supabase/supabase-swift/blob/main/Examples/UserManagement/README.md This SQL script creates a 'profiles' table with row-level security policies, configures a Realtime publication for the table, and initializes a storage bucket for user avatars. It requires an existing Supabase project and appropriate database permissions to execute. ```sql -- Create a table for public "profiles" create table profiles ( id uuid references auth.users not null, updated_at timestamp with time zone, username text unique, avatar_url text, website text, primary key (id), unique(username), constraint username_length check (char_length(username) >= 3) ); alter table profiles enable row level security; create policy "Public profiles are viewable by everyone." on profiles for select using ( true ); create policy "Users can insert their own profile." on profiles for insert with check ( auth.uid() = id ); create policy "Users can update own profile." on profiles for update using ( auth.uid() = id ); -- Set up Realtime! begin; drop publication if exists supabase_realtime; create publication supabase_realtime; commit; alter publication supabase_realtime add table profiles; -- Set up Storage! insert into storage.buckets (id, name) values ('avatars', 'avatars'); create policy "Avatar images are publicly accessible." on storage.objects for select using ( bucket_id = 'avatars' ); create policy "Anyone can upload an avatar." on storage.objects for insert with check ( bucket_id = 'avatars' ); ``` -------------------------------- ### Create a Bucket with cURL Source: https://github.com/supabase/supabase-swift/blob/main/Tests/StorageTests/__Snapshots__/StorageBucketAPITests/StorageBucketAPITests-testCreateBucket.1.txt Use this cURL command to create a new bucket in Supabase Storage. Ensure you replace 'http://example.com/bucket' with your actual Supabase project URL. ```curl curl \ --request POST \ --header "Content-Type: application/json" \ --header "X-Client-Info: storage-swift/2.24.4" \ --data "{\"public\":true,\"id\":\"newbucket\",\"name\":\"newbucket\"}" \ "http://example.com/bucket" ``` -------------------------------- ### GET /users Source: https://github.com/supabase/supabase-swift/blob/main/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.iLikeAllOf.txt Retrieves a list of users from the Supabase database based on specific email filtering criteria. ```APIDOC ## GET /users ### Description Retrieves user records from the database. Supports filtering via query parameters such as email patterns. ### Method GET ### Endpoint https://{project-ref}.supabase.co/users ### Parameters #### Query Parameters - **email** (string) - Optional - Filter users by email pattern using PostgREST operators (e.g., ilike). - **select** (string) - Optional - Specifies which columns to return. ### Request Example ```bash curl \ --header "Accept: application/json" \ --header "Content-Type: application/json" \ --header "X-Client-Info: postgrest-swift/x.y.z" \ "https://example.supabase.co/users?email=ilike(all).%7B%25@supabase.io,%25@supabase.com%7D&select=*" ``` ### Response #### Success Response (200) - **data** (array) - A list of user objects matching the query criteria. #### Response Example [ { "id": "uuid", "email": "user@supabase.io" } ] ``` -------------------------------- ### Test Supabase Documentation Build Source: https://github.com/supabase/supabase-swift/blob/main/AGENTS.md Command to test the DocC documentation build for the Supabase Swift project, ensuring it compiles without warnings. ```bash # Test documentation build make test-docs ``` -------------------------------- ### Reset Local Database Source: https://github.com/supabase/supabase-swift/blob/main/Examples/README.md Use `supabase db reset` to reset your local Supabase database. This command is useful for starting with a clean database state during development. ```bash # Run migrations supabase db reset ``` -------------------------------- ### Link and Push Migrations to Remote Supabase Source: https://github.com/supabase/supabase-swift/blob/main/Examples/README.md Link your local project to your remote Supabase project using `supabase link` and then push your database migrations with `supabase db push`. This synchronizes your local database schema with the remote one. ```bash # Link to your project supabase link --project-ref your-project-ref # Push migrations to remote supabase db push ``` -------------------------------- ### Run Swift Tests on iOS Source: https://github.com/supabase/supabase-swift/blob/main/README.md Execute tests for the iOS platform using Xcodebuild. This command verifies that your changes pass all existing tests. ```bash make PLATFORM=IOS XCODEBUILD_ARGUMENT=test xcodebuild ```