Telligent Community provides a robust set of in-process APIs that allow developers to interact with its data. These APIs are accessed through an API service that is similar to dependency injection but will only return the first instance of a class or interface that implements or extends the IAPI interface. As a developer you can also create your own APIs and expose them to the API service.
Why should I Create My Own API
APIs are a contract we have with developers developing on our platform. It is our agreement that we will not change an API in a way that would break an existing integration or customization without providing ample notice. There are also many vendors, independent software developers and partners who create various custom components for the platform that may want to expose similar API contracts for their products. For that reason subscribing an API to the API service makes sense as it will allow developers to access the custom API the exact same way as all other APIs. In previous versions all community APIs were handled via a sealed static class so third party developers had to create their own version of this or an equivalent method in their own code. This made for a disjointed experience.
If you are creating a small customization not meant for redistribution, or a distributable component that has not public facing API then you don't need to do this. This feature mainly targets distributable components and community APIs, however you can use this anytime you want to expose an API.
Exposing Your API To Telligent Community
Implementing the Correct Interface
There are a few considerations you need to take into account when designing your API in order to avoid issues later. As you will see when you register an interface, an instance of your API is only created when the application starts or right before the plugins initialize. This means your API class should be stateless or at least only stores data at the instance level that applies to all interactions with the API within the process such as additional services or constant values. While APIs do not have to be singleton classes, the easiest way to develop them is to approach them like they are singleton classes. Your class can also not be static.
You can make your class ready to subscribe to the API service by implementing the IApi interface. Implementing this interface is easy as it has no members to implement so other than adding the interface to your class definition it requires no additional work.
In this example we have an API to expose called PersonService and it exposes a method to get a random name. In order to prepare our class to be included in the API service, we add the IAPI interface:
public class PersonService : Telligent.Evolution.Extensibility.Api.IApi { public string GetRandomName() { return "Wally"; } }
Registering Your API
Once you have implemented the interface, you have identify
Additionally, if your API service already implements an interface of its own or an abstract class, you can make either of those implement IAPI and the API Service is smart enough to recognize the inheritance chain or the fact your interface is further extended by IAPI.