- Home
- Workspace
- Development
- Creating API for custom modules
Creating API for custom modules
Introduction
If you created a custom module for ONLYOFFICE and added it to ONLYOFFICE Workspace following these instructions, you can also create an API for this module.
creating an API for a custom module
- Create a Class Library (
ASC.Api.Sample) project and place it in the...module\ASC.Api\ASC.Api.Samplefolder.IMPORTANT!!! The output DLL file name must beASC.Api.*.dll; - Add the required references from
...\web\studio\ASC.Web.Studio\bin\:ASC.Api.dll ASC.Web.Sample.dll - Create the
SampleApiclass and implement theIApiEntryPointinterface:public class SampleApi : IApiEntryPoint { public string Name { get { return "sample"; } } } - Create public methods with the specific attributes:
[Attributes.Create("create", false)] public SampleClass Create(string value) { return SampleDao.Create(value); }The attribute specifies the type of method, the path by which this method will be called, the authorization and verification of the tariff plan in it. The possible options are shown below:
CreateAttribute(string path, bool requiresAuthorization = true, bool checkPayment = true) //corresponds to the "POST" request UpdateAttribute(string path, bool requiresAuthorization = true, bool checkPayment = true) //corresponds to the "PUT" request DeleteAttribute(string path, bool requiresAuthorization = true, bool checkPayment = true) //corresponds to the "DELETE" request ReadAttribute(string path, bool requiresAuthorization = true, bool checkPayment = true) //corresponds to the "GET" requestThe
requiresAuthorizationandcheckPaymentparameters are optional and defqult totrue. - Set the output path in the project properties as:
<OutputPath>..\..\..\web\studio\ASC.Web.Studio\bin\</OutputPath> <DocumentationFile>..\..\..\web\studio\ASC.Web.Studio\bin\ASC.Api.Sample.XML</DocumentationFile>so that builds are output to the
web\studio\ASC.Web.Studio\binfolder. - The project can be built manually or using the builder. For the latter, add the following lines to the
build\msbuild\build.projfile:<ProjectToBuild Include="$(ASCDir)module\ASC.Api\ASC.Api.Sample\ASC.Api.Sample.csproj"/>and run the
build\Build.batfile. - IMPORTANT Add
ASC.Api.Sample.SampleApito theweb\studio\ASC.Web.Studio\web.autofac.configfile:<component type="ASC.Api.Sample.SampleApi, ASC.Api.Sample" service="ASC.Api.Interfaces.IApiEntryPoint, ASC.Api" name="sample"/> - Build the project, start the website, and test the method by making a query with jQuery:
$.ajax({ type: "POST", url: "http://localhost:port/api/2.0/sample/create.json", data: {value: "create"} });
Article with the tag:
Browse all tags