Implementing a plugin Rest API

33 views
Skip to first unread message

Antoine Musso

unread,
Jul 6, 2022, 8:17:57 AM7/6/22
to Repo and Gerrit Discussion

Hello,

I wrote a plugin to list events registered in Gerrit and I got the ssh commands working exactly as I intended including passing parameters. Unfortunately I could not figure out how to implement the REST API.  Based on my findings, I went to propose an example plugin, the intent is to provide a collection of hello messages in different languages with the ability to fetch the message for a given language, the API would look like:

GET /plugins/example-plugin/hello?pp=1
{
    "english": "hello world",
    "french": "bonjour tout le monde",
    "german": "Hallo Welt"
}

And to retrieve a message in a specific language:

GET /plugins/example-plugin/hello/english?pp=1
{
    "language": "english",
    "message": "hello world",
}

The Gerrit-HttpModule in the manifest points at a ServletModule which bind the collection and the resource then serve("/hello*").with(HelloWorldRestApiServlet.class) , I somehow get the list of messages, but can't figure out how to filter for a specific entry in the collection :-\

Maybe the RestApiServlet is not the proper approach? I have seen RestApiModule but it seems to be to extend the existing Gerrit API (eg /branch, /project).

The have send the half broken code to the examples plugin: https://gerrit-review.googlesource.com/c/plugins/examples/+/340134  and I could use some guidances, ideally I would like to write some documentation in dev-plugins.html since that creating a REST API might be a common use case.

-- 
Antoine "hashar" Musso
Release Engineering
Reply all
Reply to author
Forward
0 new messages