APIs are essential when it comes to software development. It allows software to communicate with each other to exchange information. In the beginning, when learning to make API calls, it can be a challenge using tools such as cURL in the terminal, FETCH in the frontend or backend option such as Express. Postman is a great tool for understanding the process of making API calls and getting feedback on the response of those calls. It provides a visual interface and allows developers to get a sense of the workflow which can provide easier transitions to using other tools such as cURL or Express.
In this tutorial, we will be using Postman to make API requests to Livepeer Video Services to get a better understanding on building an application similar to Twitch or YouTube. The Livepeer Video Services API consists of the standard features for users such as creating new live streams, recording the streams and getting a list of their streams. By leveraging Livepeer’s decentralized network for transcoding, it will be easier and cost effective to scale for in the future.
Step 1: Get access to Postman
Go to Postman’s website and sign up for a free account.
You can use their web browser tool or download the desktop version. For this tutorial, we will use the desktop version with Mac OS, but it is also available for Windows and Linux.
Step 2: Get access to Livepeer Video Services
Now that we have access to these two services, let’s start interacting with them.
Step 3: Get anAPI key
With the API key, we will start going through the Stream section of Livepeer Video Services' API Reference. The reference uses the cURL command but we will do this using Postman instead.
To learn more about streaming Livepeer Video Services with the cURL command, visit the tutorial How To Stream With Livepeer Video Service’s RTMP API
Step 4:
Step 5: Create a stream
Now select the Body tab and then underneath select the raw radio button
Then click the the Text drop down menu and select the JSON option
In the text box field below, paste the following code which is from the Livepeer Video Services' API reference docs. You can change the name to whatever you want as this is for the name of your stream
{ "name": "First Stream", "profiles": [ { "name": "720p", "bitrate": 2000000, "fps": 30, "width": 1280, "height": 720 }, { "name": "480p", "bitrate": 1000000, "fps": 30, "width": 854, "height": 480 }, { "name": "360p", "bitrate": 500000, "fps": 30, "width": 640, "height": 360 } ] }
Now let’s get the stream we just created
Step 6: Retrieve a stream
Step 7: Get a list of streams
Step 8: Toggling a stream
Replace GET with Patch and insert the URL for for toggling recording https://livepeer.com/api/stream/{id}/record and replace {id} with the one you have at the end of Step 5
Now we will toggle the recording on by putting the following in body, just as we did in Step 5
{ “record”: true }
Click the blue send button and it should confirm with a response of status 204 meaning that the request went through
Step 9: Update a stream
Select Patch and insert the URL for updating a stream https://livepeer.com/api/stream/{id} and replace {id} with the one you have at the end of Step 5
Now we will not have the recording on and suspend the stream by putting the following in body, just as we did in Step 5
{ “record”: false, “suspend”: true }
Click the blue send button and it should confirm with a response of status 204 meaning that the request went through
Step 10: Delete a stream
Now that you are able to use Postman to interact with Livepeer Video Services' API, take your skills to another level using cURL. To learn more, check out the tutorial How to Stream With Livepeer Video Service’s RTMP API.
First Published here