This Package for Laravel Client Consume API (Web Service)
In Your Project you must install guzzlehttp/guzzle
version 6.2 or latest version.
Install via "composer"
$ composer require rdj/client "dev-master"
Add the manual in composer.json
Step 1
{
...
"require"{
"rdj/client" : "dev-master"
}
}
Step 2
$ composer update
Register the Provider in the config/app.php
file:
'providers' => [
....
Rdj\Client\ClientServiceProvider::class,
]
Add facade aliases in the same file config / app.php
:
'aliases' => [
....
'Client' => Rdj\Client\Facades\Client::class,
]
Publish the package configuration file using the following command:
$ php artisan vendor:publish
Edit file .env
add the following code:
WEB_SERVER_URI=your_web_server_uri (e.g: https://webserver.com/ )
BASE=your_base (e.g: int/ or eks/ or mobile/ or api/v1/ )
....
use Client;
Class YourController extends Controller
{
....
public function getData()
{
$getdata = Client::setEndpoint('your_endpoint')
->setHeaders([])
->setQuery([])
->get();
return response()->json( $getdata );
}
}
....
use Client;
Class YourController extends Controller
{
....
public function getData()
{
$getdata = Client::setEndpoint('your_endpoint')
->setHeaders(['authorization' => 'your_token'])
->setQuery([])
->get();
return response()->json( $getdata );
}
}
....
use Client;
Class YourController extends Controller
{
....
public function getData(Request $request)
{
$search = $request->search;
$getdata = Client::setEndpoint('your_endpoint')
->setHeaders(['authorization' => 'your_token'])
->setQuery(['search' => $search])
->get();
return response()->json( $getdata );
}
}
....
use Client;
Class YourController extends Controller
{
....
public function postData(Request $request)
{
$param_post = $request->all();
$getdata = Client::setEndpoint('your_endpoint')
->setHeaders(['authorization' => 'your_token'])
->setBody($param_post)
->post();
return response()->json( $getdata );
}
}
....
use Client;
Class YourController extends Controller
{
....
public function postDataMultipart(Request $request)
{
$param_post = $request->all();
$getdata = Client::setEndpoint('your_endpoint')
->setHeaders(['authorization' => 'your_token'])
->setBody($param_post)
->post('multipart');
return response()->json( $getdata );
}
}
....
use Client;
Class YourController extends Controller
{
....
public function DeleteData($id)
{
$getdata = Client::setEndpoint('your_endpoint/'.$id)
->setHeaders(['authorization' => 'your_token'])
->deleted();
return response()->json( $getdata );
}
}
- Fork it (https://github.com/ranggadarmajati/LaravelClient/fork)
- Create your feature branch (
git checkout -b feature/fooBar
) - Commit your changes (
git commit -am 'Add some fooBar'
) - Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request
This Package have license under MIT License