Added syntax highlighting
This commit is contained in:
@@ -14,25 +14,29 @@ Download the PHP library from Github, and require in your script like so:
|
|||||||
### Creating Request
|
### Creating Request
|
||||||
So you're probably wondering how using Unicorn makes creating requests in PHP easier, let's look at a working example:
|
So you're probably wondering how using Unicorn makes creating requests in PHP easier, let's look at a working example:
|
||||||
|
|
||||||
|
```php
|
||||||
$response = Unicorn::post("http://httpbin.org/post", array( "Accept" => "application/json" ),
|
$response = Unicorn::post("http://httpbin.org/post", array( "Accept" => "application/json" ),
|
||||||
array(
|
array(
|
||||||
"parameter" => 23,
|
"parameter" => 23,
|
||||||
"foo" => "bar"
|
"foo" => "bar"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
```
|
||||||
|
|
||||||
### File Uploads
|
### File Uploads
|
||||||
To upload files in a multipart form representation simply place an @ symbol before the path:
|
To upload files in a multipart form representation simply place an @ symbol before the path:
|
||||||
|
|
||||||
|
```php
|
||||||
$response = Unicorn::post("http://httpbin.org/post", array( "Accept" => "application/json" ),
|
$response = Unicorn::post("http://httpbin.org/post", array( "Accept" => "application/json" ),
|
||||||
array(
|
array(
|
||||||
"file" => "@/tmp/file.txt"
|
"file" => "@/tmp/file.txt"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
```
|
||||||
|
|
||||||
### Custom Entity Body
|
### Custom Entity Body
|
||||||
Sending a custom body such as a JSON Object rather than a string or form style parameters we utilize json_encode for the body:
|
Sending a custom body such as a JSON Object rather than a string or form style parameters we utilize json_encode for the body:
|
||||||
|
```php
|
||||||
$response = Unicorn::post("http://httpbin.org/post", array( "Accept" => "application/json" ),
|
$response = Unicorn::post("http://httpbin.org/post", array( "Accept" => "application/json" ),
|
||||||
json_encode(
|
json_encode(
|
||||||
array(
|
array(
|
||||||
@@ -41,13 +45,16 @@ Sending a custom body such as a JSON Object rather than a string or form style p
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
```
|
||||||
|
|
||||||
### Request Reference
|
### Request Reference
|
||||||
|
```php
|
||||||
Unicorn::get($url, $headers = array());
|
Unicorn::get($url, $headers = array());
|
||||||
Unicorn::post($url, $headers = array(), $body = NULL);
|
Unicorn::post($url, $headers = array(), $body = NULL);
|
||||||
Unicorn::put($url, $headers = array(), $body = NULL);
|
Unicorn::put($url, $headers = array(), $body = NULL);
|
||||||
Unicorn::patch($url, $headers = array(), $body = NULL);
|
Unicorn::patch($url, $headers = array(), $body = NULL);
|
||||||
Unicorn::delete($url, $headers = array());
|
Unicorn::delete($url, $headers = array());
|
||||||
|
```
|
||||||
|
|
||||||
`url`
|
`url`
|
||||||
Endpoint, address, or uri to be acted upon and requested information from.
|
Endpoint, address, or uri to be acted upon and requested information from.
|
||||||
|
|||||||
Reference in New Issue
Block a user