Call application in php

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

This Sample PHP Application demonstrates the use of EnableX Platform’s JavaScript Toolkit to develop multiparty video chat application. You might also require an App Server of your choice to support this App. It allows developers to ramp up on app development by hosting on their own devices.

EnableX/Group-Video-Call-Conferencing-Sample-Application-in-PHP

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Читайте также:  Javascript if str search

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Multi-Party RTC: A Sample Web App using PHP and EnableX Web Toolkit

The Sample Web App demonstrates the use of APIs for EnableX platform to develop basic Multi-Party RTC (Real Time Communication) Application. The main motivation behind this application is to demonstrate usage of APIs and allow developers to ramp up on app by hosting on their own devices instead of directly using servers.

RTC Applications hosted on EnableX platform run natively on supported set of web browsers without any additional plugin downloads.

This basic Multi-Party RTC Application is generated using HTML, CSS, Bootstrap, JavaScript, jQuery, PHP and EnxRtc (The EnableX Web Toolkit).

When developing a Client Application with EnxRtc.js, make sure to include the updated EnxRtc.js polyfills from https://developer.enablex.io/video-api/client-api/web-toolkit/ for RTCPeerConnection and getUserMedia. Otherwise your application will not work in web browsers.

  • Register with EnableX [https://portal.enablex.io/cpaas/trial-sign-up/]
  • Create your Application
  • Get your App ID and App Key
  • Clone this repository git clone https://github.com/EnableX/Group-Video-Call-Conferencing-Sample-Application-in-PHP.git —recursive

Please note —recursive option. Repo should be cloned recursively to download client app.

The Application needs to run on https. So, you need to use a valid SSL Certificate for your Domain and point your application to use them.

However you may use self-signed Certificate to run this application locally. There are many Web Sites to get a Self-Signed Certificate generated for you, Google it. Few among them are:

As you have Certificate or created a Self-Signed Certificate, create a directory «certs» under your Sample Web App Directory. Copy your Certificate files (.key and .crt files) to this directory.

Before you can run this application, configure the service by editing api/config.php file to meet project requirement:

define("API_URL", "https://api.enablex.io/v1"); define("APP_ID", "YOUR_APP_ID"); define("APP_KEY", "YOUR_APP_KEY");
  • Open a browser and go to https://yourdomain.com/path-to-sample-app/client/. The browser should load the App.
  • Allow access to Camera and Mic as and when prompted to start your first RTC Call through EnableX
  • You need to Room ID to join. We have added a «Create Room» link below the login form. Click it to get a Room-Id prefilled in the form.
  • You can share the Room-ID with anyone to join your Conference.

EnableX Server API is a Rest API service meant to be called from Partners’ Application Server to provision video enabled meeting rooms. API Access is given to each Application through the assigned App ID and App Key. So, the App ID and App Key are to be used as Username and Password respectively to pass as HTTP Basic Authentication header to access Server API.

For this application, the following Server API calls are used:

  • https://developer.enablex.io/video-api/server-api/rooms-route/#create-room — To create room to carry out a video session
  • https://developer.enablex.io/video-api/server-api/rooms-route/#create-token — To create Token for the given Room to join a session

Client End Point Application uses Web Toolkit EnxRtc.js to communicate with EnableX Servers to initiate and manage RTC Communications.

About

This Sample PHP Application demonstrates the use of EnableX Platform’s JavaScript Toolkit to develop multiparty video chat application. You might also require an App Server of your choice to support this App. It allows developers to ramp up on app development by hosting on their own devices.

Источник

How to make API calls in PHP on the server?

Before diving into developing a full-stack application, you first choose a stack. Which technology do you want to use for your client-side, what database will your project need, and what language will your server consume? These are a few basic questions that you need to decide on before starting development.

Several server technologies are available these days. One of the most popular is PHP, supporting approximately 78% of the sites running on the Internet. And since almost all applications consume APIs one way or another, you would also need to call them in your PHP server. In this piece, let’s look at making API calls in a PHP server and then rendering the response on an HTML frontend. We will also briefly look at PHP as a server language. So without any further ado, let’s jump in!

PHP

PHP was released back in 1994. It is a recursive acronym for “PHP: Hypertext Preprocessor”. It is a server-side language adopted by the likes of Meta for their product “Facebook”. WordPress that powers 43% of the Internet is written in PHP. In PHP, you can integrate several databases, including MySQL, PostgreSQL, Oracle, Sybase, etc. It is simple, efficient, and provides great flexibility when developing servers.

Consuming APIs in PHP

Since PHP is a server-side language, we will create a basic PHP server and use simple HTML and JavaScript on the client-side to request the server. We will do this in a bunch of steps to make it easier to follow along.

→ STEP #1

Instead of looking up APIs on the Internet, let’s go to RapidAPI Hub and create an account if you haven’t already.

Once you have logged in, you will see thousands of APIs. I have already found a freemium Random Facts API that we can use. To use this API, you need to subscribe to it first. You can do this by clicking on Subscribe to Test button.

Once you click the button, you will be redirected to another page where different available subscription packages will be shown. Let’s go with the free one for now. After all this, you will be redirected back to the original page. Here you will have a key x-rapidapi-key . Save it somewhere. It will be used later in the application.

→ STEP #2

You can skip this step if you already have PHP installed in your computer. If not, you can download it from here. Once downloaded, install it in your computer.

→ STEP #3

Since PHP is a server-side language, you need to set up a server. You can use any server you want. For this piece, I am using XAMPP that you can download from here. Install it once it is done downloading. Afterward, run XAMPP and start the Apache Web Server.

→ STEP #4

Now navigate to where you have installed XAMPP. Inside it, you will find a directory called htdocs . Create a folder inside this directory called php-api-call . Now open this directory in your preferred code editor.

→ STEP #5

Now create another directory called server inside php-api-call . Inside this directory, create file called random-fact.php . In this file, you will write the logic of making an API call to Random Facts API. On the Random Facts API page, you will find code snippets of how you can use this API with different languages. Since we are using PHP, let’s choose the (PHP) cURL from the dropdown.

Copy the code snippet and paste it inside the random-fact.php file. I have provided the snippet below for quick access:

php
php
header("Access-Control-Allow-Origin: *");
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://random-facts2.p.rapidapi.com/getfact",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"x-rapidapi-host: random-facts2.p.rapidapi.com",
"x-rapidapi-key: YOUR-RAPID-API-KEY"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err)
echo "cURL Error #:" . $err;
> else
echo $response;
>
?>

Replace the value of the x-rapidapi-key in the above code snippet with the API key you saved earlier.

→ STEP #6

Now you need to create a simple frontend using HTML. For this, create an index.html file in the root directory and paste the following code inside it:

html
html>
lang="en">
charset="UTF-8" />
http-equiv="X-UA-Compatible" content="IE=edge" />
name="viewport" content="width=device-width, initial-scale=1.0" />
Calling API in PHP
id="fact">
onclick="callAPI()">Make API call
async function callAPI()
const fact = document.getElementById('fact');
try
const res = await fetch(
`http://localhost/php-api-call/server/random-fact.php`
);
const response = await res.json();
fact.innerText = response.Fact;
> catch (err)
console.log(err);
>
>

The code is making an API call to our PHP server when the Make API call button is clicked. I will hit the random-fact.php endpoint and receive a response that is then rendered on the screen. Now run this file and click on the Make API call button. You will see something like this on the screen:

Wrap Up

This guide was an introduction to consuming APIs in PHP. We hope that now you can start using APIs in your awesome PHP projects.

Источник

Оцените статью