{"componentChunkName":"component---node-modules-carrotsearch-gatsby-theme-apidocs-templates-documentation-page-js","path":"/rest-api-basics/","result":{"data":{"html":{"frontmatter":{"id":"rest-api-basics","title":"REST API basics"},"html":"<article>\n  <h1>REST API basics</h1>\n\n  <p id=\"f45164a4\">\n    You can use the REST API to call Lingo3G clustering from non-Java languages.\n    This article explains the basic REST API workflow.\n  </p>\n\n  <section id=\"installation\">\n    <h2>\n        <a class=\"anchor\" href=\"#installation\" aria-hidden=\"true\"><svg aria-hidden=\"true\" height=\"16\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"/></svg></a>Installation and running\n      </h2>\n\n    <ol>\n      <li>\n        <p id=\"installation:cd5659f7\">\n          <a href=\"/installation/#installation\">Install Lingo3G</a> on your\n          machine.\n        </p>\n      </li>\n\n      <li>\n        <p id=\"installation:2c8591a4\">\n          Start the\n          <a href=\"/basic-concepts/#apis-and-tools:document-clustering-server\">Lingo3G Document Clustering Server (DCS)</a>\n          application located in the <code>dcs/</code>\n          folder of your Lingo3G installation.\n        </p>\n\n        <ul>\n          <li id=\"installation:49a61077\">On Windows, run the <code>dcs.cmd</code> script.</li>\n          <li id=\"installation:86cd8b22\">On Linux and Mac, run the <code>dcs</code> script.</li>\n        </ul>\n\n        <p id=\"installation:e71987e6\">\n          If the DCS starts successfully, you should see a terminal window with\n          messages similar to the following:\n        </p>\n\n        <div class=\"gatsby-highlight\">\n    <pre class=\"language-none\"><code data-language=\"none\">16:59:55: DCS context initialized [algorithms: [Lingo3G], templates: [frontend-default]]\n16:59:55: Service started on port 8080.\n16:59:55: The following contexts are available:\n  http://localhost:8080/          DCS Root\n  http://localhost:8080/doc       Documentation\n  http://localhost:8080/frontend  End-user apps\n  http://localhost:8080/javadoc   Java API Javadoc\n  http://localhost:8080/service   REST API</code></pre>\n  </div>\n\n        <p id=\"installation:3b7b0808\">\n          The DCS binds to port <code>8080</code> by default. To select a\n          different port, pass the <code>--port</code>\n          option to the launch script, for example:\n        </p>\n\n        <div class=\"gatsby-highlight\">\n    <pre class=\"language-none\"><code data-language=\"none\">> dcs --port 8081</code></pre>\n  </div>\n      </li>\n    </ol>\n  </section>\n\n  <section id=\"rest-endpoints\">\n    <h2>\n        <a class=\"anchor\" href=\"#rest-endpoints\" aria-hidden=\"true\"><svg aria-hidden=\"true\" height=\"16\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"/></svg></a>REST endpoints\n      </h2>\n\n    <p id=\"rest-endpoints:7861f89f\">\n      Lingo3G REST API is available at the <code>/service</code> URL prefix and\n      exposes the following endpoints:\n    </p>\n\n    <dl>\n      <dt>\n        <a href=\"#/cluster\"><code>/cluster</code></a>\n      </dt>\n      <dd>Clusters the documents you provide.</dd>\n\n      <dt>\n        <a href=\"#/list\"><code>/list</code></a>\n      </dt>\n      <dd>\n        Returns the list of clustering algorithms and languages the REST API\n        supports.\n      </dd>\n    </dl>\n\n    <p id=\"rest-endpoints:3d437ec6\">\n      Lingo3G REST API is <em>stateless</em> — the clustering results\n      depend only on the contents of the documents you provide. This means, you\n      can easily load-balance multiple DCS instances for redundancy and\n      performance reasons.\n    </p>\n\n    <p id=\"rest-endpoints:5f77fd9c\">\n      The following sections show how to invoke Lingo3G clustering through the\n      REST API. For detailed information and more examples, see the\n      <a href=\"http://localhost:8080/service/openapi/swagger/index.html\">OpenAPI Swagger documentation</a>\n      (or alternatively\n      <a href=\"http://localhost:8080/service/openapi/rapidoc/index.html\">RapiDoc</a>,\n      <a href=\"http://localhost:8080/service/openapi/redoc/index.html\">ReDoc</a>,\n      <a href=\"http://localhost:8080/service/openapi/dcs.yaml\">OpenAPI YAML</a>).\n    </p>\n\n    <section id=\"/cluster\" class=\"api\">\n      <h3>\n        <a class=\"anchor\" href=\"#/cluster\" aria-hidden=\"true\"><svg aria-hidden=\"true\" height=\"16\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"/></svg></a><code>/cluster</code>\n      </h3>\n\n      <p id=\"/cluster:619238f3\">\n        Clusters the documents you provide. To invoke clustering, make a\n        <code>POST</code> request to the <code>/cluster</code>\n        endpoint with a JSON object like this:\n      </p>\n\n      <figure id=\"/cluster:example-request\">\n        <div class=\"gatsby-highlight\">\n    <pre class=\"language-json\"><code data-language=\"json\"><span class=\"gatsby-highlight-code-line\">POST /service/cluster HTTP/<span class=\"token number\">1.1</span>\n</span><span class=\"gatsby-highlight-code-line\">Host<span class=\"token operator\">:</span> localhost<span class=\"token operator\">:</span><span class=\"token number\">8080</span>\n</span><span class=\"gatsby-highlight-code-line\">Content-Type<span class=\"token operator\">:</span> text/json\n</span>\n<span class=\"token punctuation\">{</span>\n  <span class=\"token property\">\"language\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"English\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token property\">\"algorithm\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Lingo3G\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token property\">\"parameters\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token property\">\"clusters\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token property\">\"maxClusterSize\"</span><span class=\"token operator\">:</span> <span class=\"token number\">0.8</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token property\">\"documents\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n    <span class=\"token punctuation\">{</span>\n      <span class=\"token property\">\"title\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Data Mining in Python\"</span><span class=\"token punctuation\">,</span>\n      <span class=\"token property\">\"content\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Collection of libraries for machine learning.\"</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span>\n      <span class=\"token property\">\"title\"</span> <span class=\"token operator\">:</span> <span class=\"token string\">\"KDD Lab: knowledge discovery from large spatial data.\"</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span>\n      <span class=\"token property\">\"title\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Data Mining\"</span><span class=\"token punctuation\">,</span>\n      <span class=\"token property\">\"snippet\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n        <span class=\"token string\">\"Data mining uses machine learning ...\"</span><span class=\"token punctuation\">,</span>\n        <span class=\"token string\">\"... automated knowledge discovery tools.\"</span>\n      <span class=\"token punctuation\">]</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">}</span></code></pre>\n  </div>\n        <figcaption>\n          <p>Example <code>/cluster</code> request headers and body.</p>\n        </figcaption>\n      </figure>\n\n      <p id=\"/cluster:2d0d4412\">The request JSON object can contain the following properties:</p>\n\n      <dl>\n        <dt id=\"/cluster:language\" class=\"api\">language</dt>\n        <dd>\n          <p id=\"/cluster:36eb5a1b\">\n            The language in which to perform clustering. Use<a href=\"#/list\"><code>/list</code></a>\n            to get the list of supported languages.\n          </p>\n        </dd>\n\n        <dt id=\"/cluster:algorithm\" class=\"api\">algorithm</dt>\n        <dd>\n          <p id=\"/cluster:f6fee08f\">The clustering algorithm to use, set to <code>Lingo3G</code>.</p>\n        </dd>\n\n        <dt id=\"/cluster:parameters\" class=\"api\">parameters</dt>\n        <dd>\n          <p id=\"/cluster:f6c16e0e\">\n            Lingo3G parameter overrides. The object you provide must follow the\n            <a href=\"/lingo3g-parameters/\">Lingo3G parameters object</a>\n            structure. You can provide only the parameters you would like to\n            customize.\n          </p>\n\n          <p id=\"/cluster:81ad765a\">\n            You can\n            <a href=\"/clustering-workbench-app/#user-interface:parameters-json-export\">export the parameters JSON</a>\n            object from Lingo3G Clustering Workbench.\n          </p>\n        </dd>\n\n        <dt id=\"/clustering:documents\" class=\"api\">documents</dt>\n        <dd>\n          <p id=\"/cluster:cc07d6a1\">\n            An array of documents for clustering. Each array element must be an\n            object representing one document. Each document can define one or\n            more fields to cluster. Field names can be arbitrary, such as\n            <code>title</code> or <code>body</code>, values must be strings or\n            arrays of strings.\n          </p>\n\n          <p id=\"/cluster:f6ea0a25\">\n            Lingo3G clusters all of the document content you provide. If your\n            data contains more fields for presentation purposes, exclude them\n            from the clustering request.\n          </p>\n\n          <p id=\"/cluster:6beb3dc0\">\n            See\n            <a href=\"/basic-concepts/#documents-for-clustering\">Documents for clustering</a>\n            for recommendations about the content you submit for clustering.\n          </p>\n        </dd>\n      </dl>\n\n      <p id=\"/cluster:3d072132\">\n        All properties of the request JSON are optional in the standard\n        configuration of Lingo3G DCS. The default value of\n        <code>language</code> is <code>English</code>, <code>algorithm</code> is\n        <code>Lingo3G</code> and <code>parameters</code> and\n        <code>documents</code> are empty. Therefore, the minimal meaningful\n        request can contain only the <code>documents</code> array. To change the\n        request property defaults or create custom request templates, see\n        <a href=\"/rest-api-request-templates/\">Request templates</a>.\n      </p>\n\n      <p id=\"/cluster:ff34f8f8\">\n        When making the request, you must set the\n        <code>Content-Type</code> header to <code>text/json</code>.\n      </p>\n\n      <p id=\"/cluster:3ea0d688\">\n        If clustering is successful, the response is a JSON object like this:\n      </p>\n\n      <figure id=\"/cluster:example-response\">\n        <div class=\"gatsby-highlight\">\n    <pre class=\"language-json\"><code data-language=\"json\"><span class=\"token punctuation\">{</span>\n  <span class=\"token property\">\"clusters\"</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n    <span class=\"token punctuation\">{</span>\n      <span class=\"token property\">\"labels\"</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n        <span class=\"token string\">\"Data Mining\"</span>\n      <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n      <span class=\"token property\">\"documents\"</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n        <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n        <span class=\"token number\">2</span>\n      <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n      <span class=\"token property\">\"clusters\"</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span> <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n      <span class=\"token property\">\"score\"</span> <span class=\"token operator\">:</span> <span class=\"token number\">1.0</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span>\n      <span class=\"token property\">\"labels\"</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n        <span class=\"token string\">\"Knowledge Discovery\"</span>\n      <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n      <span class=\"token property\">\"documents\"</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n        <span class=\"token number\">1</span><span class=\"token punctuation\">,</span>\n        <span class=\"token number\">2</span>\n      <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n      <span class=\"token property\">\"clusters\"</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span> <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n      <span class=\"token property\">\"score\"</span> <span class=\"token operator\">:</span> <span class=\"token number\">0.9829125404836723</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">}</span></code></pre>\n  </div>\n\n        <figcaption>\n          <p>Example <code>/cluster</code> response.</p>\n        </figcaption>\n      </figure>\n\n      <p id=\"/cluster:37a299a4\">The response JSON has the following properties:</p>\n\n      <dl class=\"narrow\">\n        <dt>clusters</dt>\n        <dd>\n          <p id=\"/cluster:bd5fed60\">\n            An array of top-level\n            <a href=\"/basic-concepts/#clusters\">clusters</a>. Each cluster\n            has the following properties:\n          </p>\n\n          <dl class=\"narrow\">\n            <dt>labels</dt>\n            <dd>\n              <p id=\"/cluster:f4dcf7c6\">One or more labels describing the cluster.</p>\n            </dd>\n\n            <dt>documents</dt>\n            <dd>\n              <p id=\"/cluster:9823187c\">\n                An array of indices of documents in the cluster. Each element is\n                a 0-based index of the document in the\n                <a href=\"#/clustering:documents\"><code>documents</code></a>\n                array you provided in the clustering request.\n              </p>\n            </dd>\n\n            <dt>clusters</dt>\n            <dd>\n              <p id=\"/cluster:04c44bc0\">\n                An array of subclusters of this cluster. The array may be empty\n                if there was not enough data to create a cluster hierarchy or\n                you disabled\n                <a href=\"/lingo3g-parameters/#hierarchy.maxHierarchyDepth\">hierarchical</a>\n                clustering.\n              </p>\n            </dd>\n\n            <dt>score</dt>\n            <dd>\n              <p id=\"/cluster:e28d86e3\">\n                The cluster's quality score. The score is not normalized in any\n                way but represents relative quality of each cluster within this\n                response.\n              </p>\n            </dd>\n          </dl>\n        </dd>\n      </dl>\n\n      <p id=\"/cluster:e8933914\">\n        The example JSON response contains two clusters:\n        <em>Data Mining</em> and <em>Knowledge Discovery</em>, each containing\n        two documents. Document <code>2</code>\n        is present in both clusters.\n      </p>\n\n      <p id=\"/cluster:c4ff7f8b\">\n        To send a clustering request to the REST API running on localhost:8080\n        with\n        <code>curl</code>, use the following command:\n      </p>\n\n      <figure id=\"/cluster:curl\">\n        <div class=\"gatsby-highlight\">\n    <pre class=\"language-none\"><code data-language=\"none\">curl -X POST --header \"Content-Type: text/json\" --data-binary @cluster-request.json \"http://localhost:8080/service/cluster?indent\"</code></pre>\n  </div>\n\n        <figcaption>\n          <p>Calling REST API using <code>curl</code>.</p>\n        </figcaption>\n      </figure>\n    </section>\n\n    <section id=\"/list\" class=\"api\">\n      <h3>\n        <a class=\"anchor\" href=\"#/list\" aria-hidden=\"true\"><svg aria-hidden=\"true\" height=\"16\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"/></svg></a>/list\n      </h3>\n\n      <p id=\"/list:3649a295\">\n        Returns the list of supported clustering algorithm-language pairs. To\n        fetch the list, make a <code>GET</code> request at the\n        <code>/list</code>\n        endpoint. The JSON response is a JSON object like this:\n      </p>\n\n      <figure id=\"/list:example-response\">\n        <div class=\"gatsby-highlight\">\n    <pre class=\"language-json\"><code data-language=\"json\"><span class=\"token punctuation\">{</span>\n  <span class=\"token property\">\"algorithms\"</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token property\">\"Lingo3G\"</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n      <span class=\"token string\">\"Dutch\"</span><span class=\"token punctuation\">,</span>\n      <span class=\"token string\">\"English\"</span>\n    <span class=\"token punctuation\">]</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token property\">\"templates\"</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n    <span class=\"token string\">\"frontend-default\"</span>\n  <span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">}</span></code></pre>\n  </div>\n\n        <figcaption>\n          <p>Example <code>/list</code> response.</p>\n        </figcaption>\n      </figure>\n\n      <p id=\"/list:fae3003c\">\n        Note that each algorithm has an associated list of language codes it\n        supports. The <code>templates</code> array lists the available\n        <a href=\"/rest-api-request-templates/\">request templates </a>.\n      </p>\n    </section>\n  </section>\n\n  <section id=\"java-models\">\n    <h2>\n        <a class=\"anchor\" href=\"#java-models\" aria-hidden=\"true\"><svg aria-hidden=\"true\" height=\"16\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"/></svg></a>Java models\n      </h2>\n\n    <p id=\"java-models:b6da63c1\">\n      If your software is Java-based, instead of the direct\n      <a href=\"/java-api-basics/\">Lingo3G Java API</a>, you may\n      <a href=\"/basic-concepts/#tools-and-apis:apis:rest-or-java-api\">choose</a>\n      to call Lingo3G REST API from your Java code. In this case, instead of\n      handling JSON creation and parsing by hand, you can use Lingo3G model\n      classes like this:\n    </p>\n\n    <figure id=\"java-models:example\">\n      <div class=\"gatsby-highlight\">\n    <pre class=\"language-java\"><code data-language=\"java\"><span class=\"token class-name\">Lingo3GClusteringAlgorithm</span> algorithm <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Lingo3GClusteringAlgorithm</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nalgorithm<span class=\"token punctuation\">.</span>clusters<span class=\"token punctuation\">.</span>maxClusterSize<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span><span class=\"token number\">1.0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token class-name\">ClusterRequest</span> request <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">ClusterRequest</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nrequest<span class=\"token punctuation\">.</span>algorithm <span class=\"token operator\">=</span> <span class=\"token class-name\">Lingo3GClusteringAlgorithm</span><span class=\"token punctuation\">.</span>NAME<span class=\"token punctuation\">;</span>\nrequest<span class=\"token punctuation\">.</span>language <span class=\"token operator\">=</span> <span class=\"token string\">\"English\"</span><span class=\"token punctuation\">;</span>\nrequest<span class=\"token punctuation\">.</span>parameters <span class=\"token operator\">=</span> <span class=\"token class-name\">Attrs</span><span class=\"token punctuation\">.</span><span class=\"token function\">extract</span><span class=\"token punctuation\">(</span>algorithm<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nrequest<span class=\"token punctuation\">.</span>documents <span class=\"token operator\">=</span>\n    <span class=\"token class-name\">Stream</span><span class=\"token punctuation\">.</span><span class=\"token function\">of</span><span class=\"token punctuation\">(</span>\n            <span class=\"token string\">\"Data Mining in Python\"</span><span class=\"token punctuation\">,</span>\n            <span class=\"token string\">\"Knowledge Discovery and Data Mining Lab\"</span><span class=\"token punctuation\">,</span>\n            <span class=\"token string\">\"Knowledge Discovery tools\"</span><span class=\"token punctuation\">)</span>\n        <span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span>\n            value <span class=\"token operator\">-></span> <span class=\"token punctuation\">{</span>\n              <span class=\"token class-name\">ClusterRequest</span><span class=\"token punctuation\">.</span><span class=\"token class-name\">Document</span> doc <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">ClusterRequest</span><span class=\"token punctuation\">.</span><span class=\"token class-name\">Document</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n              doc<span class=\"token punctuation\">.</span><span class=\"token function\">setField</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"title\"</span><span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n              <span class=\"token keyword\">return</span> doc<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n        <span class=\"token punctuation\">.</span><span class=\"token function\">collect</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">Collectors</span><span class=\"token punctuation\">.</span><span class=\"token function\">toList</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre>\n  </div>\n\n      <figcaption>\n        <p>Using Java model classes to build Lingo3G REST API request JSONs.</p>\n      </figcaption>\n    </figure>\n\n    <p id=\"java-models:7a1cffdd\">\n      You can serialize model instances into JSON using the\n      <a href=\"https://github.com/FasterXML/jackson\">Jackson</a> library. See\n      the <code>examples-dcs</code> folder of Lingo3G distribution for complete\n      working examples of this approach.\n    </p>\n  </section>\n</article>","tableOfContents":[{"heading":"Installation and running","anchor":"installation"},{"heading":"REST endpoints","anchor":"rest-endpoints","sections":[{"heading":"/cluster","anchor":"/cluster"},{"heading":"/list","anchor":"/list"}]},{"heading":"Java models","anchor":"java-models"}]}},"pageContext":{"slug":"/rest-api-basics/"}},"staticQueryHashes":["1164750013"]}