### Retrieve Resources using find() Source: https://context7.com/shopify/pyactiveresource/llms.txt Shows how to fetch collections or individual resources using the find() method. Includes examples for query parameters, array/dictionary filters, and nested resource path resolution. ```python from pyactiveresource import activeresource class Person(activeresource.ActiveResource): _site = 'http://api.example.com' people = Person.find() person = Person.find(1) people = Person.find(name='Arnold', active='true') people = Person.find(vars=['a', 'b', 'c']) people = Person.find(filter={'status': 'active'}) class Comment(activeresource.ActiveResource): _site = 'http://api.example.com/posts/$post_id/' comments = Comment.find(post_id=5) comment = Comment.find(10, post_id=5) ``` -------------------------------- ### Performing Low-Level HTTP Operations Source: https://context7.com/shopify/pyactiveresource/llms.txt Shows how to instantiate a Connection object and perform standard HTTP verbs like GET, POST, PUT, DELETE, and HEAD with automatic formatting. ```python conn = connection.Connection(site='http://api.example.com', user='username', password='secret', timeout=30, format=formats.JSONFormat) response = conn.get('/people.json') data = conn.get_formatted('/people/1.json') conn.post('/people.json', data=b'{"person": {"name": "New"}}') conn.put('/people/1.json', data=b'{"person": {"name": "Updated"}}') conn.delete('/people/1.json') conn.head('/people/1.json') ``` -------------------------------- ### Adding URL Parameters to Requests Source: https://github.com/shopify/pyactiveresource/blob/master/README.md Demonstrates how to append query parameters to a GET request by passing a dictionary to the `find` method. ```APIDOC ## Adding URL Parameters to Requests ### Description This snippet explains how to include query parameters in your GET requests. By passing a dictionary of parameters to the `find()` method, you can filter, paginate, or otherwise modify the collection of resources returned by the API. ### Method GET ### Endpoint `/people.json?param1=value1¶m2=value2` ### Parameters #### Query Parameters - **page** (integer) - Optional - The page number for pagination. - **member** (boolean) - Optional - Filter for members. - ... (other supported query parameters) ### Request Example ```python # For GET http://api.people.com:3000/people.json?page=30&member=true results = Person.find(params={'page': 30, 'member': True}) ``` ### Response #### Success Response (200) - A collection of resources matching the specified query parameters. #### Response Example ```json [ { "id": 10, "first": "Alice", "last": "Smith" } // ... potentially more results based on query ] ``` ``` -------------------------------- ### Perform Custom HTTP Operations with PyActiveResource Source: https://context7.com/shopify/pyactiveresource/llms.txt Demonstrates how to execute custom HTTP verbs (GET, POST, PUT, DELETE, HEAD) on resource instances or classes. These methods allow interaction with non-standard API endpoints. ```python response = Person.delete('deactivate', reason='terminated') person = Person.find(1) profile = person.get('profile') response = person.post('notify', b'{"message": "Hello"}') response = person.put('promote', b'', position='Manager') response = person.delete('deactivate') response = person.head('status') ``` -------------------------------- ### GET /people Source: https://context7.com/shopify/pyactiveresource/llms.txt Retrieves a collection of people resources from the remote API. ```APIDOC ## GET /people ### Description Retrieves a list of all person resources from the configured site. ### Method GET ### Endpoint /people.{format} ### Parameters #### Path Parameters - **format** (string) - Required - The data format (json or xml). ### Request Example GET /people.json ### Response #### Success Response (200) - **people** (array) - List of person objects. #### Response Example [ {"id": 1, "name": "Arnold"}, {"id": 2, "name": "Eb"} ] ``` -------------------------------- ### GET /people/{id} Source: https://context7.com/shopify/pyactiveresource/llms.txt Retrieves a specific person resource by its unique identifier. ```APIDOC ## GET /people/{id} ### Description Fetches details for a specific person resource. ### Method GET ### Endpoint /people/{id}.{format} ### Parameters #### Path Parameters - **id** (integer) - Required - The unique identifier of the person. - **format** (string) - Required - The data format (json or xml). ### Request Example GET /people/1.json ### Response #### Success Response (200) - **person** (object) - The person resource details. #### Response Example { "id": 1, "name": "Arnold" } ``` -------------------------------- ### Custom Resource Methods (GET/POST/PUT/DELETE/HEAD) in Python Source: https://context7.com/shopify/pyactiveresource/llms.txt PyActiveResource allows executing custom HTTP methods (GET, POST, PUT, DELETE, HEAD) on resources for non-standard RESTful actions. These can be called as class methods or instance methods, accepting a method name and optional parameters or data payloads. This enables interaction with custom API endpoints. ```python from pyactiveresource import activeresource class Person(activeresource.ActiveResource): _site = 'http://api.example.com' # Class-level custom GET # GET http://api.example.com/people/retrieve.json?name=Matz result = Person.get('retrieve', name='Matz') print(result) # [{'id': 1, 'name': 'Matz'}] # Class-level custom POST # POST http://api.example.com/people/hire.json?department=engineering response = Person.post('hire', department='engineering') print(response.code) # 200 # Class-level custom PUT # PUT http://api.example.com/people/promote.json?level=senior response = Person.put('promote', b'{"bonus": 5000}', level='senior') # Class-level custom DELETE # DELETE http://api.example.com/people/fire.json?id=1 response = Person.delete('fire', id=1) ``` -------------------------------- ### Refresh Resource Data with reload() in Python Source: https://context7.com/shopify/pyactiveresource/llms.txt The `reload()` instance method fetches the latest data for a resource from the server via a GET request, updating the resource's attributes in place. This is useful for discarding local modifications or ensuring the resource object reflects the current server state. ```python from pyactiveresource import activeresource class Person(activeresource.ActiveResource): _site = 'http://api.example.com' # GET http://api.example.com/people/1.json person = Person.find(1) print(person.name) # 'Original Name' # Modify locally person.name = 'Modified Name' print(person.name) # 'Modified Name' # Reload from server (discards local changes) # GET http://api.example.com/people/1.json person.reload() print(person.name) # 'Original Name' ``` -------------------------------- ### Configuring ActiveResource Models and Formats Source: https://context7.com/shopify/pyactiveresource/llms.txt Demonstrates how to define ActiveResource classes with specific formats (JSON/XML) and how to switch formats dynamically at runtime. ```python class JsonPerson(activeresource.ActiveResource): _site = 'http://api.example.com' _format = formats.JSONFormat class XmlPerson(activeresource.ActiveResource): _site = 'http://api.example.com' _format = formats.XMLFormat JsonPerson.format = formats.XMLFormat person = JsonPerson.find(1) ``` -------------------------------- ### Create a New Resource Source: https://github.com/shopify/pyactiveresource/blob/master/README.md Demonstrates creating a new resource by submitting a JSON body. The library automatically parses the 'Location' header from the response to set the object's ID. ```python tyler = Person.create({ 'first': 'Tyler' }) tyler.id ``` -------------------------------- ### Define Resource Models with PyActiveResource Source: https://context7.com/shopify/pyactiveresource/llms.txt Demonstrates how to define resource models by inheriting from ActiveResource. It covers site configuration, authentication methods, custom primary keys, and nested resource URL patterns. ```python from pyactiveresource import activeresource class Person(activeresource.ActiveResource): _site = 'http://api.example.com' class SecurePerson(activeresource.ActiveResource): _site = 'http://username:password@api.example.com' class ApiPerson(activeresource.ActiveResource): _site = 'http://api.example.com' _user = 'api_user' _password = 'api_secret' _headers = {'X-Api-Key': 'your-api-key', 'Accept': 'application/json'} _timeout = 30 class User(activeresource.ActiveResource): _site = 'http://api.example.com' _primary_key = 'username' class Address(activeresource.ActiveResource): _site = 'http://api.example.com/people/$person_id/' ``` -------------------------------- ### Basic Model Configuration Source: https://github.com/shopify/pyactiveresource/blob/master/README.md Demonstrates how to define a model class that inherits from ActiveResource and sets the site URL for API requests. ```APIDOC ## Basic Model Configuration ### Description This snippet shows the fundamental setup for a PyActiveResource model, including inheriting from `ActiveResource` and specifying the `_site` attribute to point to the base URL of the REST API. ### Method N/A (Class definition) ### Endpoint N/A (Class definition) ### Parameters N/A ### Request Example ```python from pyactiveresource import activeresource as ar class Person(ar.ActiveResource): _site = 'http://api.people.com:3000/people' ``` ### Response N/A ``` -------------------------------- ### Retrieve and Manage Remote Resources Source: https://context7.com/shopify/pyactiveresource/llms.txt Demonstrates how to fetch collections of resources, access pagination metadata from response headers, and copy resource collections while preserving metadata. ```python people = Person.find() print(len(people)) print(people[0].name) print(people.metadata) people_copy = people.copy() print(people_copy.metadata == people.metadata) ``` -------------------------------- ### Serialize Resource Objects to JSON, XML, and Dictionaries Source: https://context7.com/shopify/pyactiveresource/llms.txt Explains how to convert resource objects into different formats for storage or transmission. Includes options for root elements, pretty-printing, and header suppression. ```python person = Person({'id': 1, 'name': 'Tyler', 'email': 'tyler@example.com'}) data = person.to_dict() json_str = person.to_json(root=False) xml_str = person.to_xml(root='user', header=False, pretty=True, dasherize=False) ``` -------------------------------- ### Finding a Collection of Resources Source: https://github.com/shopify/pyactiveresource/blob/master/README.md Explains how to retrieve a list of resources using the `find` method without any arguments, expecting a JSON array in response. ```APIDOC ## Finding a Collection of Resources ### Description This snippet shows how to retrieve a collection of resources. Calling the `find()` method without any arguments on a model class results in a GET request to the collection endpoint, expecting a JSON array of resources in the response. ### Method GET ### Endpoint `/people.json` ### Parameters N/A ### Request Example ```python # Assuming a response like: # [ # {"id":1,"first":"Tyler","last":"Durden"}, # {"id":2,"first":"Tony","last":"Stark"} # ] people = Person.find() print(people[0].first) # Output: Tyler print(people[1].first) # Output: Tony ``` ### Response #### Success Response (200) - An array of resource objects, where each object has attributes corresponding to the JSON keys. #### Response Example ```json [ { "id": 1, "first": "Tyler", "last": "Durden" }, { "id": 2, "first": "Tony", "last": "Stark" } ] ``` ``` -------------------------------- ### Create New Resource with create() in Python Source: https://context7.com/shopify/pyactiveresource/llms.txt The `create()` class method instantiates a resource with provided attributes and saves it to the server via a POST request. It returns the created resource object, with its ID typically parsed from the 'Location' header of the response. It supports creating nested resources by passing prefix options. ```python from pyactiveresource import activeresource class Person(activeresource.ActiveResource): _site = 'http://api.example.com' # POST http://api.example.com/people.json # Request body: {"person": {"name": "Tyler", "email": "tyler@example.com"}} # Expected response: 201 Created with Location: /people/5 person = Person.create({'name': 'Tyler', 'email': 'tyler@example.com'}) print(person.id) # 5 (parsed from Location header) print(person.name) # 'Tyler' # Nested resource creation class Address(activeresource.ActiveResource): _site = 'http://api.example.com/people/$person_id/' # POST http://api.example.com/people/5/addresses.json address = Address.create( {'street': '123 Main St', 'city': 'New York'}, prefix_options={'person_id': 5} ) ``` -------------------------------- ### Run Project Tests Source: https://github.com/shopify/pyactiveresource/blob/master/README.md Command to execute the test suite for the pyactiveresource project. ```bash python setup.py test ``` -------------------------------- ### Retrieve Resource from Custom URL with find_one() Source: https://context7.com/shopify/pyactiveresource/llms.txt Explains how to use find_one() to fetch a resource from a non-standard or custom URL path, optionally including query parameters. ```python from pyactiveresource import activeresource class Soup(activeresource.ActiveResource): _site = 'http://api.example.com' soup = Soup.find_one(from_='/what_kind_of_soup.json') soup = Soup.find_one(from_='/special_menu.json', day='monday') ``` -------------------------------- ### Retrieve First Matching Resource with find_first() Source: https://context7.com/shopify/pyactiveresource/llms.txt Demonstrates the find_first() method to retrieve a single object from a collection query. It returns the first match or None if no results are found. ```python from pyactiveresource import activeresource class Person(activeresource.ActiveResource): _site = 'http://api.example.com' person = Person.find_first(name='Tyler') if person: print(person.name) nobody = Person.find_first(name='NonExistent') ``` -------------------------------- ### Authentication and Headers Source: https://github.com/shopify/pyactiveresource/blob/master/README.md Illustrates how to set custom headers, such as authentication tokens, for all requests made by a model. ```APIDOC ## Authentication and Headers ### Description This snippet demonstrates how to configure authentication or other custom headers for API requests by setting the `_headers` class variable within your model. This is useful for passing API keys, tokens, or other required metadata. ### Method N/A (Class definition) ### Endpoint N/A (Class definition) ### Parameters N/A ### Request Example ```python from pyactiveresource import activeresource as ar token = 'your_auth_token_here' class Person(ar.ActiveResource): _site = 'http://api.people.com:3000/people' _headers = { 'auth': token } ``` ### Response N/A ``` -------------------------------- ### Create Resource Source: https://github.com/shopify/pyactiveresource/blob/master/README.md Create a new resource by submitting its JSON representation. The response includes a 'Location' header with the URL of the new resource. ```APIDOC ## POST /people.json ### Description Creates a new person resource. The JSON representation of the resource is sent as the request body. A 'Location' header in the response indicates the URL of the newly created resource. ### Method POST ### Endpoint /people.json ### Request Body - **first** (string) - Required - The first name of the person. - **last** (string) - Required - The last name of the person. ### Request Example ```json { "first": "Tyler", "last": "Durden" } ``` ### Response #### Success Response (201) - **Location** (string) - The URL of the newly created resource. #### Response Example ``` Location: http://api.people.com:3000/people/2 ``` ### Code Example ```python typer = Person.create({ 'first': 'Tyler' }) typer.id # 2 ``` ``` -------------------------------- ### POST /people Source: https://context7.com/shopify/pyactiveresource/llms.txt Creates a new person resource. ```APIDOC ## POST /people ### Description Creates a new person record on the server. ### Method POST ### Endpoint /people.{format} ### Parameters #### Request Body - **name** (string) - Required - The name of the person. ### Request Example { "person": { "name": "New Person" } } ### Response #### Success Response (201) - **id** (integer) - The ID of the created resource. #### Response Example { "id": 3, "name": "New Person" } ``` -------------------------------- ### Configure authentication headers Source: https://github.com/shopify/pyactiveresource/blob/master/README.md Shows how to set custom HTTP headers, such as authentication tokens, for requests made by the ActiveResource model. ```python class Person(ar.ActiveResource): _site = 'http://api.people.com:3000/people' _headers = { 'auth': token } ``` -------------------------------- ### Retrieve resources using find Source: https://github.com/shopify/pyactiveresource/blob/master/README.md Illustrates how to fetch single resources or collections from a REST endpoint. The library automatically maps JSON response fields to object attributes. ```python # Fetch a single resource person = Person.find(1) # Fetch a collection people = Person.find() ``` -------------------------------- ### Handling HTTP Exceptions Source: https://context7.com/shopify/pyactiveresource/llms.txt Illustrates how to catch and handle specific exceptions raised by the connection layer, such as 404, 401, 403, 422, and server-side errors. ```python try: person = Person.find(999) except connection.ResourceNotFound as e: print(f"Person not found: {e.url}") except connection.UnauthorizedAccess: print("Invalid credentials") except connection.ResourceInvalid as e: print("Validation failed") except connection.ServerError as e: print(f"Server error: {e.code}") ``` -------------------------------- ### Read Resource Source: https://github.com/shopify/pyactiveresource/blob/master/README.md Find resources by specifying query parameters. The result is a collection of resources. ```APIDOC ## GET /people.json ### Description Retrieves a collection of people resources based on the provided query parameters. ### Method GET ### Endpoint /people.json ### Query Parameters - **page** (integer) - Optional - The page number to retrieve. - **member** (string) - Optional - Filters the results to include only members matching the value. ### Request Example ``` people = Person.find(page=30, member='true') ``` ### Response #### Success Response (200) - **people** (array) - A list of person objects. #### Response Example ```json [ { "id": 1, "first": "John", "last": "Doe" }, { "id": 2, "first": "Jane", "last": "Smith" } ] ``` ``` -------------------------------- ### Finding a Single Resource Source: https://github.com/shopify/pyactiveresource/blob/master/README.md Shows how to retrieve a single resource by its ID using the `find` method, expecting a JSON object in response. ```APIDOC ## Finding a Single Resource ### Description This snippet explains how to fetch a specific resource using its unique identifier. The `find()` method is called with the resource ID, and PyActiveResource expects a JSON representation of the resource in the response, which is then deserialized into a Python object. ### Method GET ### Endpoint `/people/{id}.json` ### Parameters #### Path Parameters - **id** (integer) - Required - The unique identifier of the resource to retrieve. ### Request Example ```python # Assuming Person class is configured as above # Expects a response like: {"id":1,"first":"Tyler","last":"Durden"} person = Person.find(1) # Accessing attributes print(person.first) # Output: Tyler print(type(person)) # Output: ``` ### Response #### Success Response (200) - **id** (integer) - The unique identifier of the person. - **first** (string) - The first name of the person. - **last** (string) - The last name of the person. - ... (other attributes from the JSON response) #### Response Example ```json { "id": 1, "first": "Tyler", "last": "Durden" } ``` ``` -------------------------------- ### Define a REST-enabled model class Source: https://github.com/shopify/pyactiveresource/blob/master/README.md Demonstrates how to create a class that inherits from ActiveResource and configures the site endpoint. This enables the class to perform REST operations against the specified URL. ```python from pyactiveresource import activeresource as ar class Person(ar.ActiveResource): _site = 'http://api.people.com:3000/people' ``` -------------------------------- ### Check Resource Existence with exists() in Python Source: https://context7.com/shopify/pyactiveresource/llms.txt The `exists()` method checks if a resource is present on the server using a HEAD request. It can be used for top-level resources or nested resources by providing appropriate prefix options. It returns a boolean indicating existence. ```python from pyactiveresource import activeresource class Person(activeresource.ActiveResource): _site = 'http://api.example.com' # HEAD http://api.example.com/people/1.json if Person.exists(1): print('Person exists') person = Person.find(1) else: print('Person not found') # Check with prefix options for nested resources class Address(activeresource.ActiveResource): _site = 'http://api.example.com/people/$person_id/' # HEAD http://api.example.com/people/5/addresses/10.json if Address.exists(10, person_id=5): print('Address exists for person 5') ``` -------------------------------- ### Save Resource Changes with save() in Python Source: https://context7.com/shopify/pyactiveresource/llms.txt The `save()` instance method persists resource changes. For new resources (without an ID), it performs a POST request. For existing resources, it performs a PUT request. It returns `True` on success and `False` if validation errors occur, providing access to error details via the `errors` attribute. ```python from pyactiveresource import activeresource class Store(activeresource.ActiveResource): _site = 'http://api.example.com' # Create a new resource (no id) # POST http://api.example.com/stores.json # Request body: {"store": {"name": "General Store"}} store = Store({'name': 'General Store'}) success = store.save() # Returns True on success print(store.id) # ID assigned by server # Update an existing resource # PUT http://api.example.com/stores/1.json # Request body: {"store": {"id": 1, "name": "General Store", "manager_id": 3}} store.manager_id = 3 success = store.save() # Returns True on success, False on validation error # Handle validation errors class Person(activeresource.ActiveResource): _site = 'http://api.example.com' person = Person({'email': 'invalid'}) if not person.save(): # Server returned 422 with: {"errors": {"email": ["is invalid"]}} print(person.errors.full_messages()) # ['email is invalid'] print(person.errors.on('email')) # 'is invalid' ``` -------------------------------- ### Delete a Resource Source: https://github.com/shopify/pyactiveresource/blob/master/README.md Explains how to destroy a resource using the delete method, which triggers a DELETE HTTP request to the resource's URL. ```python tyler.delete() ``` -------------------------------- ### Update an Existing Resource Source: https://github.com/shopify/pyactiveresource/blob/master/README.md Shows how to update a resource using the save method. It sends a PUT request with the modified attributes and expects a 204 status code. ```python tyler.first = 'Tyson' tyler.save() ``` -------------------------------- ### Perform String and Data Transformations Source: https://context7.com/shopify/pyactiveresource/llms.txt Utilizes the util module for Rails-style string manipulation (pluralization, camelization) and data serialization/deserialization between Python dictionaries and JSON/XML formats. ```python from pyactiveresource import util # String manipulation print(util.pluralize('person')) print(util.camelize('active_resource')) # Serialization json_str = util.to_json({'name': 'Tyler'}, root='person') xml_bytes = util.to_xml({'id': 1}, root='person') # Encoding query = util.to_query({'name': 'Tyler', 'tags': ['a', 'b']}) ``` -------------------------------- ### Handling Nested Resources Source: https://github.com/shopify/pyactiveresource/blob/master/README.md Demonstrates how nested JSON objects in the response are automatically converted into nested objects on the Python resource. ```APIDOC ## Handling Nested Resources ### Description This snippet illustrates how PyActiveResource handles nested JSON structures within API responses. Complex JSON objects are automatically deserialized into corresponding nested objects, allowing for attribute access on these nested structures. ### Method GET ### Endpoint `/people/{id}.json` ### Parameters #### Path Parameters - **id** (integer) - Required - The unique identifier of the resource to retrieve. ### Request Example ```python # Assuming a response like: {"id":1,"first":"Tyler","address":{"street":"Paper St.","state":"CA"}} tyler = Person.find(1) # Accessing nested attributes print(type(tyler.address)) # Output: (or similar dynamic class) print(tyler.address.street) # Output: Paper St. ``` ### Response #### Success Response (200) - **id** (integer) - The unique identifier of the person. - **first** (string) - The first name of the person. - **address** (object) - A nested object containing address details. - **street** (string) - The street name. - **state** (string) - The state. #### Response Example ```json { "id": 1, "first": "Tyler", "address": { "street": "Paper St.", "state": "CA" } } ``` ``` -------------------------------- ### Handle Nested Resources and Automatic Conversion Source: https://context7.com/shopify/pyactiveresource/llms.txt Shows how PyActiveResource automatically maps nested JSON objects and arrays into typed resource classes. Primitives are preserved as standard Python types. ```python class Address(activeresource.ActiveResource): _site = 'http://api.example.com' class Store(activeresource.ActiveResource): _site = 'http://api.example.com' class Person(activeresource.ActiveResource): _site = 'http://api.example.com' person = Person.find(1) print(type(person.address)) # store = Store.find(1) print(type(store.addresses[0])) # print(store.websites) # ['http://example.com', 'http://store.example.com'] ``` -------------------------------- ### Mocking API Responses for Testing Source: https://context7.com/shopify/pyactiveresource/llms.txt Uses the http_fake utility to intercept HTTP requests and provide predefined responses, enabling isolated unit testing of ActiveResource models. ```python http_fake.initialize() http_fake.TestHandler.site = 'http://api.example.com' http_fake.TestHandler.respond_to('GET', '/people.json', {}, util.to_json([{'id': 1, 'name': 'Arnold'}], root='people')) people = Person.find() assert len(people) == 1 ``` -------------------------------- ### Delete Resource with destroy() / delete() in Python Source: https://context7.com/shopify/pyactiveresource/llms.txt The `destroy()` instance method removes a resource from the server using a DELETE request. It can be called on a resource object retrieved via `find()` or on a resource object instantiated with an ID. The `delete()` method is an alias for `destroy()`. ```python from pyactiveresource import activeresource class Person(activeresource.ActiveResource): _site = 'http://api.example.com' # Find and delete # GET http://api.example.com/people/1.json person = Person.find(1) # DELETE http://api.example.com/people/1.json person.destroy() # Or delete directly with attributes person = Person({'id': 5}) person.destroy() # DELETE http://api.example.com/people/5.json ``` -------------------------------- ### Delete Resource Source: https://github.com/shopify/pyactiveresource/blob/master/README.md Delete a resource using either a class or instance method. An empty response with a 200 status code indicates successful deletion. ```APIDOC ## DELETE /people/{id}.json ### Description Deletes a person resource. This can be invoked as a class or instance method. ### Method DELETE ### Endpoint /people/{id}.json ### Path Parameters - **id** (integer) - Required - The ID of the person to delete. ### Response #### Success Response (200) An empty response with a 200 status code indicates successful deletion. ### Code Example ```python typer.delete() ``` ``` -------------------------------- ### Update Resource Source: https://github.com/shopify/pyactiveresource/blob/master/README.md Update an existing resource by sending the modified JSON representation. An empty response indicates a successful update. ```APIDOC ## PUT /people/{id}.json ### Description Updates an existing person resource. The updated JSON representation is sent as the request body. A successful update returns an empty response. ### Method PUT ### Endpoint /people/{id}.json ### Path Parameters - **id** (integer) - Required - The ID of the person to update. ### Request Body - **first** (string) - Optional - The updated first name of the person. - **last** (string) - Optional - The updated last name of the person. ### Request Example ```json { "first": "Tyson" } ``` ### Response #### Success Response (204) An empty response indicates a successful update. ### Code Example ```python typer.first = 'Tyson' typer.save() # true ``` ``` -------------------------------- ### Manage Validation Errors from API Responses Source: https://context7.com/shopify/pyactiveresource/llms.txt Details how to access and manipulate validation errors returned by the server, typically via HTTP 422 status codes. Provides methods for checking validity, retrieving specific error messages, and manual error injection. ```python if not person.save(): print(person.errors.full_messages()) person.errors.clear() person.errors.add('name', 'is reserved') ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.