@freemium yep, use Laravel's HTTP Client ...
can we call api from controller
i need to call this api with content
$APPID="ajkdbajkdsb";
$AccessChannel=asbakjsb;
$RecordingUID="akjbdskjabs;
curl --location -g --request POST 'https://api.agora.io/v1/apps/'.$APPID.'/cloud_recording/acquire' \
--header 'Content-Type: application/json' \
--data-raw '{
"cname"=>$AccessChannel,
"uid"=>$RecordingUID,
"clientRequest":{
}
}
if we can call then help me in formatting this content in controller ..using laravel 8
@webrobert please help formatting in controller
@freemium what do you have so far?
@Sinnbeck i am using https://www.agora.io/en/blog/using-agora-cloud-recording-for-a-video-chat-web-app/ agora api for video call for video call i am using vue js and i want to record that calling video for that i need to call again agora api for video recording here is my controller
public function index(Request $request)
{
$users = User::where('id', '<>', Auth::id())->get();
return view('agora-chat', ['users' => $users]);
}
protected function token(Request $request)
{
$appID = env('AGORA_APP_ID');
$appCertificate = env('AGORA_APP_CERTIFICATE');
$channelName = $request->channelName;
$user = Auth::user()->name;
$role = RtcTokenBuilder::RoleAttendee;
$expireTimeInSeconds = 3600;
$currentTimestamp = now()->getTimestamp();
$privilegeExpiredTs = $currentTimestamp + $expireTimeInSeconds;
$token = RtcTokenBuilder::buildTokenWithUserAccount($appID, $appCertificate, $channelName, $user, $role, $privilegeExpiredTs);
return $token;
}
public function callUser(Request $request)
{
$data['userToCall'] = $request->user_to_call;
$data['channelName'] = $request->channel_name;
$data['from'] = Auth::id();
broadcast(new MakeAgoraCall($data))->toOthers();
//i think i need to call api from here
}
@freemium don't see the Http client in there?
I'll get you started.
$response = Http::withHeaders([
'Content-Type' => 'application/json'
])->withBody(
json_encode($yourDataAsArray)
)->post('https://api.agora.io/v1/apps/'.$APPID.'/cloud_recording/acquire')
?? i did, the code is directly linked...
use Illuminate\Support\Facades\Http;
$response = Http::post('http://example.com/users', [
'name' => 'Steve',
'role' => 'Network Administrator',
]);
T r y I t .
@Sinnbeck, I think that's a bit verbose, the example a gave will do that automatically.
$response = Http::post('http://example.com/users', $yourDataAsArray);
@webrobert oh great. Didn't know it would be posted as body/raw. Sweet 😁
I thought the array method posted what in php would be $_POST, while the withBody() method posted what in php would be php://stdin
@Sinnbeck ah, I missed the data raw bit.. though the headers are already json by default.
@webrobert ok great. Haven't used it that much, and I might need to clean up some of my implementations then. Think I always set the header explicitly
Edit 😶
By default, data will be sent using the application/json content type:
@Sinnbeck well sort of, this has been fun 🤓
// normal post json
Http::dump()->post('http://example.com/users', [
"cname" => 'test'
]);
// didn't work for body
Http::dump()->post('http://example.com/users', [
'body' => json_encode(["cname" => 'test'])
]);
// Too few arguments to function Illuminate\Http\Client\PendingRequest::withBody(),
Http::dump()->withBody(json_encode(["cname" => 'test']))
->post('http://example.com/users');
// HAD to set JSON, you were right.
Http::dump()->withBody(json_encode(["cname" => 'test']), 'application/json')
->post('http://example.com/users');
@webrobert wow interesting! So wrong and right at the same time.
Please or to participate in this conversation.