-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from exonet/tsi-EXO-3827
Add support for PATCH
- Loading branch information
Showing
16 changed files
with
568 additions
and
92 deletions.
There are no files selected for viewing
This file contains 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 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 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,61 @@ | ||
# API Resources | ||
|
||
## Getting data from a resource | ||
Get data from the attributes or relationships of a resource. See [making API calls](calls.md) for more information on | ||
how to get resources from the API. | ||
|
||
```php | ||
$dnsRecord = $client->resource('dns_records')->get('VX09kwR3KxNo'); | ||
|
||
// Show an attribute value: | ||
echo $dnsRecord->attribute('name'); | ||
|
||
// Get a related value, in this example the name of the DNS zone: | ||
echo $dnsRecord->related('zone')->get()->attribute('name'); | ||
``` | ||
|
||
## Creating a new resource | ||
Post a new resource to the API by setting its attributes and relationships: | ||
|
||
```php | ||
$record = new ApiResource('dns_records'); | ||
$record->attribute('name', 'www'); | ||
$record->attribute('type', 'A'); | ||
$record->attribute('content', '192.168.1.100'); | ||
$record->attribute('ttl', 3600); | ||
|
||
// The value of a relationship must be defined as a resource identifier. | ||
$record->relationship('zone', new ApiResourceIdentifier('dns_zones', 'VX09kwR3KxNo')); | ||
$result = $record->post(); | ||
|
||
print_r($result); | ||
``` | ||
|
||
## Modifying a resource | ||
Modify a resource by changing its attributes and/or relationships: | ||
|
||
```php | ||
$dnsRecord = $client->resource('dns_records')->get('VX09kwR3KxNo'); | ||
// Or, if there is no need to retrieve the resource from the API first you can use the following: | ||
// $dnsRecord = new ApiResource('dns_records', 'VX09kwR3KxNo'); | ||
|
||
// Change the 'name' attribute to 'changed-name'. | ||
$dnsRecord->attribute('name', 'changed-name'); | ||
|
||
// The value of a relationship must be defined as a resource identifier. | ||
$dnsRecord->relationship('dns_zone', new ApiResourceIdentifier('dns_zones', 'X09kwRdbbAxN')); | ||
|
||
// Patch the changed data to the API. | ||
$dnsRecord->patch(); | ||
``` | ||
|
||
## Deleting a resource | ||
Delete a resource with a given ID: | ||
|
||
```php | ||
$dnsRecord = $client->resource('dns_records')->get('VX09kwR3KxNo'); | ||
// Or, if there is no need to retrieve the resource from the API first you can use the following: | ||
// $dnsRecord = new ApiResource('dns_records', 'VX09kwR3KxNo'); | ||
|
||
$dnsRecord->delete(); | ||
``` |
This file contains 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 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 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 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.