- Home
- Workspace
- Development
- Creating API for the ONLYOFFICE Workspace custom modules
Creating API for the ONLYOFFICE Workspace custom modules
Introduction
If you created your own module for ONLYOFFICE and added it to ONLYOFFICE Workspace following these instructions, you can also create API for this module.
How to create API for your own module
- Create a Class Library (
ASC.Api.Sample
) project and put it to the...module\ASC.Api\ASC.Api.Sample
folder.IMPORTANT!!! The output dll file name must be "ASC.Api.*.dll"; - Connect the required references from
...\web\studio\ASC.Web.Studio\bin\
:ASC.Api.dll ASC.Web.Sample.dll
- Create the
SampleApi
class and implement theIApiEntryPoint
interface: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" requestUpdateAttribute(string path, bool requiresAuthorization = true, bool checkPayment = true) //corresponds to the "PUT" requestDeleteAttribute(string path, bool requiresAuthorization = true, bool checkPayment = true) //corresponds to the "DELETE" requestReadAttribute(string path, bool requiresAuthorization = true, bool checkPayment = true) //corresponds to the "GET" request
the
requiresAuthorization
,checkPayment
parameters are optional and have a value oftrue
by default. - 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 the builds were created at the
web\studio\ASC.Web.Studio\bin
folder. - The project can be built manually or using the builder. For the latter add the following lines to the
build\msbuild\build.proj
file:<ProjectToBuild Include="$(ASCDir)module\ASC.Api\ASC.Api.Sample\ASC.Api.Sample.csproj"/>
and run the
build\Build.bat
file. - IMPORTANT!!! Add
ASC.Api.Sample.SampleApi
to theweb\studio\ASC.Web.Studio\web.autofac.config
file:<componenttype="ASC.Api.Sample.SampleApi, ASC.Api.Sample"service="ASC.Api.Interfaces.IApiEntryPoint, ASC.Api"name="sample"/>
- Build the project, run 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"}});
Host ONLYOFFICE Workspace on your own server
Article with the tag:
Browse all tags