<commit_before># Api Resource

[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)

Simple guzzle wrapper to provide simple access to api endpoints.

## Install

Require this package with composer (Packagist) using the following command:

``` bash
$ composer require media24si/api-resource
```

Register the ApiResourceServiceProvider to the providers array in `config/app.php`

``` php
'Media24si\ApiResource\ApiResourceServiceProvider',
```

Publish vendor files (config file):
``` bash
$ art vendor:publish
```

**Optional**
Register facade in `config/app.php`:
``` php
'Api' => 'Media24si\ApiResource\Facades\ApiResource'
```

## Usage

You can use package without configuration. Just use \Api facade in controllre (or inject Media24si\ApiResource\ApiResource in function/controler).

Call your endpoints as normal guzzle request:
``` php
\Api::get('http://httpbin.org'); // you get response object
```

## Config

**base_url**
Configures a base URL for the client so that requests created using a relative URL are combined with the base_url. Same as guzzle base_url (see offcial manual).

**defaults**
Associative array of Request Options that are applied to every request created by the client. See official manual.

**default_response**
Set default response type from functions.
Possible options:
- json
- xml
- empty (default)

Setting this to json and calling `\Api::get('endpoint')` is same as leaving it empy and call `\Api::get('endpoint')->json()`

**endpoints**
Array of defined endpoints. Here you can define your aliases for calling endpoints.

Sample array:
``` php
'endpoints' => [
	'notification' => [
		'url' => 'http://httpbin.org/notification'
	],
	'categories' => [
		'url' => '/categories', // with base_url set
		'options' => [
			'query' => [
				'fields' => 'id, title'
			]
		]
	]
]
```

With endpoints defined you can make simple call `\Api::get('notification')`.
Default options can be overwriten `\Api::get('categories', ['query' => ['fields' => 'id, title, slug']])`.

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.<commit_msg>Update to the readme file<commit_after># Api Resource

[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)

A simple Guzzle wrapper, providing easy access to API endpoints.

## Install

Require this package with Composer (Packagist), using the following command:

``` bash
$ composer require media24si/api-resource
```

Register the ApiResourceServiceProvider to the providers array in `config/app.php`

``` php
'Media24si\ApiResource\ApiResourceServiceProvider',
```

Publish vendor files (config file):
``` bash
$ art vendor:publish
```

**Optional**
Register the facade in `config/app.php`:
``` php
'Api' => 'Media24si\ApiResource\Facades\ApiResource'
```

## Usage

You can use this package without any configuration. Just use the \Api facade in your controller (or inject Media24si\ApiResource\ApiResource in your function/controller).

Call your endpoints, like you would a normal Guzzle request:
``` php
\Api::get('http://httpbin.org'); // returns a response object
```

## Config

**base_url**
Configures a base URL for the client, so that requests created using a relative URL are combined with the base_url. Same as guzzle base_url. For more, see the official [manual].

**defaults**
Associative array of Request Options that are applied to every request created by the client. See the official [manual].

**default_response**
Set a default response type returned from functions.
Possible options:
- json
- xml
- empty (default)

Setting the default response to `json` and calling `\Api::get('endpoint')` is effectively the same as leaving it empty and calling `\Api::get('endpoint')->json()`

**endpoints**
Array of defined endpoints. Here you can define your aliases for endpoints.

Sample array:
``` php
'endpoints' => [
	'notification' => [
		'url' => 'http://httpbin.org/notification'
	],
	'categories' => [
		'url' => '/categories', // with base_url set
		'options' => [
			'query' => [
				'fields' => 'id, title'
			]
		]
	]
]
```

With endpoints defined you can make simple calls. A sample would be: 
``` php
\Api::get('notification')
```

Default options can be overridden: 
``` php
\Api::get('categories', ['query' => ['fields' => 'id, title, slug']])
```

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

[manual]: http://guzzle.readthedocs.org/en/latest/
{'fraction_non_alphanumeric': 0.1347720766351024, 'fraction_numerical': 0.0035234529839242457, 'mean_word_length': 4.6775, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2026297', 'n_tokens_mistral': 1421, 'n_tokens_neox': 1311, 'n_words': 487}