Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Syndeia Cloud also comes with an example Java project (Eclipse and IntelliJ) named CloudApiDemo that demonstrates how to use the REST API. This example project is available for download in the following ways.

  1. Available with the Syndeia Cloud download. Check with your admin.
  2. Available with the tutorials in all three Syndeia clients - MagicDraw plugin, Rhapsody plugin, and Syndeia Standalone.

Follow the instructions below to get started.

CloudApiDemo

This project is a Java example, that shows how to call various endpoints exposed by the Syndeia Cloud API.

Code organization

This is a Maven project with a pom.xml file that mentions all the dependencies on the external Java packages.

The source code is organized in three packages -

  • com.intercax.syndeia.domain - contains various domain model classes (like Repository, Container, Artifact, Relation etc.)
  • com.intercax.syndeia.services - contains various classes like CloudService, CoreCloudService, CloudServiceUrlHelper, GenericrestClient and ReponseTypesForGson classes
  • com.intercax.syndeia.utils - contains Either and TriFunction utility classes

A few of the subpackages of the com.intercax.syndeia.domain package, are as under -

  • com.intercax.syndeia.domain.forms - contains classes that are to used to call POST / PUT APIs to sign-up and sign-in a

user *com.intercax.syndeia.domain.responses** - contains classes that are used to deserialize the string response of Syndeia Cloud API endpoints

How do I get set up?

  • You can open this project in IntelliJ IDEA or Eclipse, or any other suitable editor like Visual Studio Code.
  • For Eclipse, use Import -> Maven -> Existing Maven Projects (by pointing to the pom.xml file) or Import -> General -> Existing projects into Workspace

(by pointing to the .project file) Before running this code, you need to make sure that the Syndeia Cloud API is running You can run the tests in com.intercax.syndeia.services.CloudServiceTests to see how a particular Syndeia Cloud API endpoint is called Alternatively, you can run the main method of the com.intercax.syndeia.CloudApiDemo project to see examples of invoking a few of the Syndeia Cloud API endpoints Both the main method and the tests assume some values (like the IP address, port, username and password) for where the Syndeia Cloud API is running. So before running either the tests or the main method, please get the required credentials from Syndeia Cloud administrator and use the relevant values.

How to extend this code (for trying out other Syndeia Cloud API endpoints)

  • You need to figure out the URL of the particular Syndeia Cloud API endpoint, whether that endpoint is exposed over HTTP

Get, Post, Put, Delete (verbs) methods, and if it accepts any parameters Typically, the Post and Put methods expect some payload (data in JSON format) for the resource that has to be created / updated on the server The Get methods might also need some values for parameters that are part of the URL Most likely, there will be a method in the com.intercax.syndeia.services.CloudServiceUrlHelper class that will be returning a correct URL by accepting (a few) parameters - if such a method is missing, you may add one accordingly Finally, you'll need to add a new method to the com.intercax.syndeia.services.CloudService class and use the URL returned by one of the methods in CloudServiceUrlHelper and then passing this URL and the type of response expected to one of the (get, getAll) methods in CoreCloudService class Typically, the methods in the com.intercax.syndeia.services.CloudService class return `Either<ErrorResponse, Response<T>>where - * *Response is one ofObjResponse(for single values),SeqResponse(for a list of values) orCreatedResponse` (if something got created on the server) T is one of the domain objects from the *com.intercax.syndeia.domain** package

Typical API calling pattern

// A method in the CloudService class

public Either<ErrorResponse, SeqResponse<Domain>> getAllDomainObjects() {
    return coreCloudService.getAll(cloudServiceUrlHelper.getXyzApiEndpointUrl(), typeOfSeqResponseOfDomain);
}

Who do I talk to?

  • No labels