PHP code example of incraigulous / rest-repositories

1. Go to this page and download the library: Download incraigulous/rest-repositories library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

incraigulous / rest-repositories example snippets


    use Incraigulous\RestRepositories\Resource;
    class PostsResource extends Resource
    {
        static $resource = 'posts'
        public static function sdk() {
            return new YourSdk();
        }
    }

	
	use Incraigulous\RestRepositories\Sdks\HttpSdk;
	
	class JsonPlaceholderSdk extends HttpSdk
	{
	    protected $endpoint = 'https://jsonplaceholder.typicode.com/';
	}
	
	$sdk = new JsonPlaceholderSdk();
	$result = $sdk->post('posts', ['title' => 'foo', 'body' => 'bar', 'userId' => 1]);

	
	use Incraigulous\RestRepositories\Sdks\HttpSdk;
	
	class ExampleSdk extends HttpSdk
	{
	    protected $endpoint = 'http://example.com/api/';
	    
	    protected function defaultHeaders()
	    {
	    	return ['Authorization' => $however->you->get->api->key];
	    }
	}
	
	$sdk = new ExampleSdk();
	$result = $sdk->post('posts', ['title' => 'foo', 'body' => 'bar', 'userId' => 1]);