Alfresco Custom Rest Api

cancel
Showing results for 
Search instead for 
Did you mean: 
sanjaybandhniya
Intermediate

Alfresco Custom Rest Api

I want to create custom rest api in alfresco.

How can i do that?

I have made following configuration.but it is not working.

<context:component-scan base-package="com.controller"></context:component-scan>

package com.tritex.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping(value = "/contract")
public class TestController {

@RequestMapping(value = "/test", method = RequestMethod.GET)
public String display() {
return "Hello World";
}
}

4 Replies
krutik_jayswal
Senior Member II

Re: Alfresco Custom Rest Api

For developing rest api in alfresco you need to use webscript.

Below links will help you in how to develop a webscript.

https://ecmarchitect.com/alfresco-developer-series-tutorials/webscripts/tutorial/tutorial.html 

Repository webscript in alfresco | Krutik Jayswal 

sanjaybandhniya
Intermediate

Re: Alfresco Custom Rest Api

I know this way to create api but i want to create in spring way using annotation and is it working same way as webscript api?

I have used REST · dgradecak/alfresco-mvc Wiki · GitHub  and it is working.

Do you have any idea about this?

rbr
Partner

Re: Alfresco Custom Rest Api

Hi,

you can create your own custom REST API in Alfresco.

First take a look at this : GitHub - covolution/quick-api: Basic example of developing a Rest API on the Alfresco Platform that ... 

Basically it's quite simple :

create java package in your repo project.

create EntityResource with CRUD actions and specify endpoint

annotate your package in a file "package-info.java"

add your package in your module-context.xml file

(<context:component-scan base-package="[put your java package here]"></context:component-scan>)

then go to :

http://localhost:8080/alfresco/api/-default-/private/[name of your api in package-info.java]/version...

darionis
Active Member

Re: Alfresco Custom Rest Api

Using webscripts and other aprocahes proposed in this thread are ok, but how come "@RestController" (initial question) does not work? I tried that myself and I see

Identified candidate component class: URL [jar:file:/usr/local/tomcat/webapps/alfresco/WEB-INF/lib/dms-test-platform-1.0-SNAPSHOT.jar!/dmstest/service/MyService.class

but the spring bean is not created and it is not mapped to a service endpoint. I am trying to figure that out, any hint will be helpfull.

Thanks!