Extend rest api

General discussion about MantisBT Plugins

Moderators: Contributor, Developer

Post Reply
federico
Posts: 17
Joined: Mar 27, 2019 12:35 pm

Extend rest api

Post by federico » May 04, 2019 12:43 am

Hello.

I would like to extend the mantisbt rest api to implement new functions (not to build something new, and it should not be necessary if the api were complete). I tried the following approaches, but none of them seems to be satisfactory for me:
  • Copy the whole rest api infrastructure to my plugin and change it to make it work: it works, but I don't like it because complicates future manteinance and compatibility
  • Change the api/rest implementation: it works too, but also complicates future manteinance and compatibility
  • Create the spected results manually using the mantisbt api: reinventing the wheel
As everyone can see, none of them are good ideas. I am not fluent with PHP, but I know the http request lifecycle, and I worked successfully on rest services development with other technologies,

¿What are the best practices to extend the existing API in a friendly way? I haven't found any documentation about this in the developers guide.

Thank you in advance.

atrol
Site Admin
Posts: 7581
Joined: Mar 26, 2008 4:37 pm
Location: Germany

Re: Extend rest api

Post by atrol » May 05, 2019 5:40 am

I have hardly any time at the moment to support such kind of questions.
You can try our Gitter channel where other devs are listening https://gitter.im/mantisbt/mantisbt

The best way to extend Mantis is to send a Pull Request on GitHub.
As an example check https://github.com/mantisbt/mantisbt/pull/1487/files (still in discussion)
https://github.com/mantisbt/mantisbt/pull/1453/files (implemented since version 2.20.0) https://www.mantisbt.org/bugs/view.php?id=25400
Please use Search before posting and read the Manual

federico
Posts: 17
Joined: Mar 27, 2019 12:35 pm

Re: Extend rest api

Post by federico » May 05, 2019 11:53 pm

Thank you atrol.

I saw the author of the rest api uses to participate in this forum, so I suposed he could explain the best practices to extend his own implementation into a plugin to keep things clear. I do not understand all the complexity behind this, because with other technologies it is quite simple, and you can choose into a wide range of solutions.

I am having an accelerate PHP course, and it reminds me the old times with ASP (before 2000), and why I decided to abandon developing with such technologies, and preferred real OO programming languages.

Starbuck
Posts: 178
Joined: Feb 13, 2006 9:53 pm
Location: USA
Contact:

Re: Extend rest api

Post by Starbuck » May 17, 2019 3:02 pm

@federico - Let's be specific. What would you like to add to the API? Maybe we can clone and adapt code, then submit a GH PR.

As to OO, PHP is now pretty good with OO. I suggest you look for existing code and model after the good examples.
If you want Mantis to work differently, use or create a plugin. Visit the Plugins forums.
Ask developers to create a plugin that you need - and motivate them to help you!

federico
Posts: 17
Joined: Mar 27, 2019 12:35 pm

Re: Extend rest api

Post by federico » May 19, 2019 2:53 am

Thank you Starbuck.

I would like to know the good practices to get a new REST api function published in the mantis plugin context, reusing the mantis API REST core infrastructure. It could be a new service (based on my custom schema), or reusing an existing core api function to incorporate to my plugin an existing one (ie. as an AJAX call). I am not sure, but mantis REST API and SOAP API implementations, seems to be a subset of methods which narrows the core api, using a different infrastructure on each case.

I do not know how to import the current REST API infrastructure to create new REST services in the plugin architecture. I tried to create new services by creating and configuring these in the core code, and it works, but I do not want to follow that path.

In Java, or .NET, I use to get whatever I want to be published from my business layer as a JSON or SOAP service, just specifying attributes to methods, which includes protocol and security considerations. Alternatively, I can also use frameworks like spring, which allows me to publish whatever business layer method as a service (SOAP or REST) with a few XML configuration lines. When I start the development of a new project, I do not use to have complete information about future publishing requirements, and this kind of implementation, allows me to decide it later, in a scalable and simple way, and respecting existing business transactionality with independency of the client consuming the service.

The best solution I found, is to create in my plugin files folder, REST service pages, and: add the mantis context security considerations, receive the function to be invoked as a parameter (to be processed at the beginning of the request), the form data to be processed, and response with the right JSON result, but I do not like it either and seems to be botched.

Starbuck
Posts: 178
Joined: Feb 13, 2006 9:53 pm
Location: USA
Contact:

Re: Extend rest api

Post by Starbuck » May 21, 2019 8:37 pm

I hear ya. My main work is with C# and Java too, so I stutter a bit when I get into PHP. I also did ASP in the 90's so we're on the same page.

You'll notice that while I helped to create and administer this plugin section, I don't post code, for lack of expertise with PHP and lack of knowledge of this specific application. HOWEVER, my goal is to help facilitate plugin development, and that's what you're trying to do...

I will discourage citing PHP as the nature of any problems. It's a very capable language, better than perl, but ultimately might get usurped by JavaScript via NodeJS or possibly Python. For our purposes let's assume and agree that we can do anything with PHP with enough knowledge of this application for What we want to do, and some code viewing for How to do it.

To the challenge : One must first understand that the SOAP web service implementation for MantisBT is the most complete, but as we know SOAP is a somewhat deprecated protocol. REST is not as complete, but it is the way to the future. So there are features that are in SOAP, not REST. My quick summary of what we want to do here, and please correct me if this is wrong, is that we want to find a function that's available in SOAP, check to make sure it's not in REST yet, and then port it to REST.

To do that, we need to get more familiar with how other functions are implemented in REST. Find a function that's implemented in both protocols and see how they're doing it. Find another function and see the commonalities. We need to get that pattern into our heads, then apply that to a new REST function.

We need to ensure that we're following the routing/pathing that has been envisioned by other developers contributing to the REST implementation. That means getting into Gitter and opening a discussion with vboctor and dregad.

Federico, are you @FSD-Christian-ISS in Gitter?
Was that you asking recently about POST via REST?
Did you get any helpful info from the REST API docs?

Is all of this going down the right path?
Good luck!
If you want Mantis to work differently, use or create a plugin. Visit the Plugins forums.
Ask developers to create a plugin that you need - and motivate them to help you!

Post Reply