Try Live Demo

REST API guide is one of the missing guides that our lovely users need to get started. In designing Ant Media Server, we’re trying to make almost everything configurable and accessible through REST API. Actually, we need to do this in order to develop a web management panel. Before starting, let’s quickly define the REST API.

What is REST API?

A REST API (also known as RESTful API) is an application programming interface (API or web API) that conforms to the constraints of REST architectural style and allows for interaction with RESTful web services. REST stands for representational state transfer and was created by computer scientist Roy Fielding.

We quickly remembered what the REST API is. So I can say that by using REST API you can almost do anything on Ant Media Server. Here is an abstract Ant Media Server API list of available methods in REST API

  • CRUD(Create/Read/Update/Delete) Operations on
  • CRUD Operations on VoD streams
  • Add/Remove RTMP Endpoints to the Streams
  • Authorize/Revoke Social Endpoints
  • Change Settings(Bitrates, Recording, Enable/Disable Object Detection, VoD Folder Path) via root app

REST Method

For the full REST API Reference, please visit the https://mirror.antmedia.io/rest 

For the rest of this guide, we try to explain how to call REST methods, give some samples and mention about Security (IP Filtering)

How to Call REST API Methods

All REST methods are the binding rest path of the app. Let me give a sample. Ant Media Server Community Edition has LiveApp and WebRTCApp by default. On the other hand, Enterprise Edition has LiveApp and WebRTCAppEE by default. The LiveApp REST methods (for instance broadcast’s get method) are available as follows

http://SERVER_ADDRESS:5080/LiveApp/rest/v2/broadcasts/{id}

Let’s make an example with the so-famous curl tool. By the way,  Postman is another great tool for testing purposes. It also generates code snippets in several programming languages such as Java, PHP, Go, Python, etc.

Create Broadcast

According to REST Reference, we should call create the method is as follows.

Important Note: Please keep in mind that the REST interface only responds to the calls that are made from 127.0.0.1 by default. If you call from any other IP Address, it does not return. For allowing more IP Addresses, take a look at the  Security section later in this post.

curl -X POST
http://localhost:5080/LiveApp/rest/v2/broadcasts/create
-H ‘content-type: application/json’
-d ‘{“name”:”test_video”}’

We can provide a Broadcast object as a parameter in JSON format. Ant Media Server returns created broadcast object in JSON format again.  The most critical field in the returned response is streamId field in JSON. We use streamId in getting broadcast.

Get Broadcast

Getting a broadcast is easier. You just need to add the streamId as a query parameter to streamId the variable as follows.

curl -X GET
‘http://localhost:5080/LiveApp/rest/broadcast/650320906975923279669775’

get method returns the Broadcast object as create method. This is the sample JSON response that get method returns.

REST API Reference

The samples below show how to call the REST methods in an easy way. In order to have a look at all methods and their parameters, you can study the REST API Reference at https://mirror.antmedia.io/rest which has a good look and feel. Thanks to the Swagger.REST API Reference

Security – IP Filtering

Ant Media Server generally runs behind an application server so you want Ant Media Server to respond to the calls that are made from specific IP ranges.  By default, Ant Media Server only responds to the calls that are made from 127.0.0.1.

In order to add IP ranges, you should go to the Settings of the app in the Web Management Panel and add
IP Ranges in CIDR notation. You can add multiple comma-separated IP Address Ranges.

 

Ant Media Server Web Panel

Conclusion

You can use the REST API of Ant Media Server as explained above. If you’re using the community edition and have questions, you can ask the community or contact@antmedia.io (a reply will be provided with the best effort). If you’re an enterprise user, you can ask contact@antmedia.io or to the specified channel allocated for you.

I hope this blog post help some guys get started easily

 

Useful Links

Ant Media Server API references.

You can start using Ant Media Server for free with all its features!

You can download native Android and iOS WebRTC SDKs and integrate them into your applications for free!

Ant Media Server Github Wiki

You would want to check Ultra Low Latency Video Streaming and 7 Use Cases and Future of Ultra-Low Latency Streaming Market.

Categories: Tutorial

Ahmet Oguz Mermerkaya

Oguz is the co-founder of Ant Media. His tech stack includes VxWorks, UML, Rhapsody in C++. Java, OSGi, Swing, JSF, Web, PHP, FFmpeg API, Native WebRTC, Java EE, Hibernate, Spring, MongoDB, MySQL, Angular, JavaScript, HTML5, Android (Native) and iOS (Native). Oguz is one of the writers of "Merhaba Android", one of the first books published in Turkey about Android app programming. His second book is about HTML5 & CSS3. He has attended several conferences and universities talking about Android, business life and technical issues. He is a member of the GDG Community and also the founder of GDG Ankara.

chatsimple
Warning: Undefined array key "promocode" in /home/mirror.antmedia.io/public_html/wp-content/themes/hestia-child/footer.php on line 70