Mahuta HTTP API

June 14, 2019 ยท View on GitHub

Overview

Persistence

Represents the writing operations.

OperationDescriptionMethodURI
index_simpleStored and index a text contentPOST/index
index_cidPin and index a CIDPOST/index/cid
index_fileStore and index a file via HTTP MultipartPOST/index/file
Query

Represents the read operations.

OperationDescriptionMethodURI
fetchGet contentGET/query/fetch/{hash}
searchSearch contentPOST/query/search

Delete

Represents the deletion operations.

OperationDescriptionMethodURI
delete_by_idUnpin and deindex a file by IDDELETE/delete/id/{id}
delete_by_hashUnpin and deindex a file by HashDELETE/delete/hash/{hash}

Configuration

Represents the configuration operations.

OperationDescriptionMethodURI
create_indexCreate an indexPOST/config/index/{index}
get_indexesGet all indexesGET/config/index

Details

[Persistence] Store and Index text

Store and Index a text

  • URL /mahuta/index
  • Method: POST
  • Header:
KeyValue
content-typeapplication/json
  • URL Params N/A
  • Data Params
NameTypeMandatoryDefaultDescription
contentStringyesContent
indexNameStringyesIndex name
indexDocIdStringnoIdentifier of the document in the index. id null, autogenerated
contentTypeStringnoContent type (mimetype)
indexFieldsObjectnoMetadata can used to query the document
{
  "content": "# Hello world,\n this is my first file stored on **IPFS**",
  "indexName": "articles",
  "indexDocId": "hello_world",
  "contentType": "text/markdown",
  "indexFields": {
      "title": "Hello world",
      "description": "Hello world this is my first file stored on IPFS",
      "author": "Gregoire Jeanmart",
      "votes": 10,
      "date_created": 1518700549,
      "tags": ["general"]
  }
}
  • Sample Request:
curl -X POST \
    'http://localhost:8040/mahuta/index' \
    -H 'content-type: application/json' \  
    -d '{"content":"# Hello world,\n this is my first file stored on **IPFS**","indexName":"articles","indexDocId":"hello_world","contentType":"text/markdown","index_fields":{"title":"Hello world","author":"Gregoire Jeanmart","votes":10,"date_created":1518700549,"tags":["general"]}}'
  • Success Response:

    • Code: 200
      Content:
{
    "status": "SUCCESS",
    "indexName": "articles",
    "id": "hello_world",
    "hash": "QmWPCRv8jBfr9sDjKuB5sxpVzXhMycZzwqxifrZZdQ6K9o"
}

[Persistence] Store and Index CID

Store and Index a text

  • URL /mahuta/index/cid
  • Method: POST
  • Header:
KeyValue
content-typeapplication/json
  • URL Params N/A
  • Data Params
NameTypeMandatoryDefaultDescription
cidStringyesContent Hash
indexNameStringyesIndex name
indexDocIdStringnoIdentifier of the document in the index. id null, autogenerated
contentTypeStringnoContent type (mimetype)
indexFieldsObjectnoMetadata can used to query the document
{
  "cid": "QmWPCRv8jBfr9sDjKuB5sxpVzXhMycZzwqxifrZZdQ6K9o",
  "indexName": "articles",
  "indexDocId": "hello_world",
  "contentType": "text/markdown",
  "indexFields": {
      "title": "Hello world",
      "description": "Hello world this is my first file stored on IPFS",
      "author": "Gregoire Jeanmart",
      "votes": 10,
      "date_created": 1518700549,
      "tags": ["general"]
  }
}
  • Sample Request:
curl -X POST \
    'http://localhost:8040/mahuta/index/cid' \
    -H 'content-type: application/json' \  
    -d '{"cid":"QmWPCRv8jBfr9sDjKuB5sxpVzXhMycZzwqxifrZZdQ6K9o","indexName":"articles","indexDocId":"hello_world","contentType":"text/markdown","index_fields":{"title":"Hello world","author":"Gregoire Jeanmart","votes":10,"date_created":1518700549,"tags":["general"]}}'
  • Success Response:

    • Code: 200
      Content:
{
    "status": "SUCCESS",
    "indexName": "articles",
    "id": "hello_world",
    "hash": "QmWPCRv8jBfr9sDjKuB5sxpVzXhMycZzwqxifrZZdQ6K9o"
}

[Persistencd] Store and Index file

Store content in IPFS and index it into the search engine

  • URL /mahuta/index/file

  • Method: POST

  • Header: N/A

  • URL Params N/A

  • Data Params

    • file: [content]
    • request:
NameTypeMandatoryDefaultDescription
indexNameStringyesIndex name
indexDocIdStringnoIdentifier of the document in the index. id null, autogenerated
contentTypeStringnoContent type (mimetype)
indexFieldsObjectnoMetadata can used to query the document
{
  "indexName": "articles",
  "indexDocId": "hello_world",
  "contentType": "text/markdown",
  "indexFields": {
      "title": "Hello world",
      "description": "Hello world this is my first file stored on IPFS",
      "author": "Gregoire Jeanmart",
      "votes": 10,
      "date_created": 1518700549,
      "tags": ["general"]
  }
}
  • Sample Request:
curl -X POST \
  http://localhost:8040/mahuta/index/file \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -F file=@/home/gjeanmart/hello.pdf \
  -F 'request='{"indexName":"articles","indexDocId":"hello_world","contentType":"text/markdown","index_fields":{"title":"Hello world","author":"Gregoire Jeanmart","votes":10,"date_created":1518700549,"tags":["general"]}}'
  • Success Response:

    • Code: 200
      Content:
{
    "status": "SUCCESS",
    "indexName": "articles",
    "id": "hello_world",
    "hash": "QmWPCRv8jBfr9sDjKuB5sxpVzXhMycZzwqxifrZZdQ6K9o"
}

[Query] Get content

Get content on IPFS by hash

  • URL http://localhost:8040/mahuta/query/fetch/{hash}

  • Method: GET

  • Header: N/A

  • URL Params N/A

  • Sample Request:

$ curl \
    'http://localhost:8040/mahuta/query/fetch/QmWPCRv8jBfr9sDjKuB5sxpVzXhMycZzwqxifrZZdQ6K9o' \
    -o hello_doc.pdf
  • Success Response:

    • Code: 200
      Content: (file)

[Query] Search contents

Search content accross an index using a dedicated query language

  • URL http://localhost:8040/mahuta/query/search
  • Method: GET or POST
  • Header:
KeyValue
content-typeapplication/json
  • URL Params
NameTypeMandatoryDefaultDescription
indexStringnoIndex to search (if null: all indexes)
pageNoIntno0Page Number
pageSizeIntno20Page Size / Limit
sortStringnoSorting attribute
dirASC/DESCnoASCSorting direction
queryStringnoQuery
  • Data Params

The search operation allows to run a multi-criteria search against an index. The body combines a list of filters :

NameTypeDescription
nameStringIndex field to perform the search
namesString[]Index fields to perform the search
operationSee belowOperation to run against the index field
valueAnyValue to compare with
OperationDescription
FULL_TEXTFull text search
EQUALSEquals
NOT_EQUALSNot equals
CONTAINSContains the word/phrase
INin the following list
GTGreater than
GTEGreater than or Equals
LTLess than
LTELess than or Equals
{
  "query": [
    {
      "name": "title",
      "operation": "CONTAINS",
      "value": "Hello"
    },
    {
      "names": ["description", "title"],
      "operation": "FULL_TEXT",
      "value": "IPFS"
    },
    {
      "name": "votes",
      "operation": "LT",
      "value": "5"
    }
  ]
}
  • Sample Request:
curl -X POST \
    'http://localhost:8040/mahuta/query/search?index=articles' \
    -H 'content-type: application/json' \  
    -d '{"query":[{"name":"title","operation":"CONTAINS","value":"Hello"},{"name":"author","operation":"EQUALS","value":"Gregoire Jeanmart"},{"name":"votes","operation":"LT","value":"5"}]}'
  • Success Response:

    • Code: 200
      Content:
{
  "elements": [
    {
        "metadata": {
          "indexName": "articles",
          "indexDocId": "hello_world",
          "contentId": "QmWPCRv8jBfr9sDjKuB5sxpVzXhMycZzwqxifrZZdQ6K9o",
          "contentType": "application/pdf",
          "indexFields": {
              "title": "Hello world",
              "description": "Hello world this is my first file stored on IPFS",
              "author": "Gregoire Jeanmart",
              "votes": 10,
              "date_created": 1518700549,
              "tags": ["general"]
          }
        },
        "payload": "# Hello world,\n this is my first file stored on **IPFS**"
    }
  ]
}
],,
"totalElements": 4,
"totalPages": 1
}