Chilkat Online Tools

Swift3 / MeiliSearch v0.24 / Update ranking rules

Back to Collection Items

func chilkatTest() {
    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    let http = CkoHttp()!
    var success: Bool

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // [
    //   "typo"
    // ]

    let jarr = CkoJsonArray()!
    jarr.addString(at: -1, value: "typo")

    http.setRequestHeader("Content-Type", value: "application/json")
    http.setRequestHeader("X-Meili-Api-Key", value: "masterKey")

    let sbRequestBody = CkoStringBuilder()!
    jarr.emitSb(sbRequestBody)

    var resp: CkoHttpResponse? = http.pTextSb("POST", url: "http://localhost:7700/indexes/indexUID/settings/ranking-rules", textData: sbRequestBody, charset: "utf-8", contentType: "application/json", md5: false, gzip: false)
    if http.lastMethodSuccess == false {
        print("\(http.lastErrorText!)")
        return
    }

    print("\(resp!.statusCode.intValue)")
    print("\(resp!.bodyStr!)")
    resp = nil

}

Curl Command

curl -X POST
	-H "X-Meili-Api-Key: masterKey"
	-H "Content-Type: application/json"
	-d '[
	"typo"
]'
http://localhost:7700/indexes/indexUID/settings/ranking-rules

Postman Collection Item JSON

{
  "name": "Update ranking rules",
  "protocolProfileBehavior": {
    "disabledSystemHeaders": {
      "content-type": true
    }
  },
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "[\n\t\"typo\"\n]\n"
    },
    "url": {
      "raw": "{{url}}/indexes/{{indexUID}}/settings/ranking-rules",
      "host": [
        "{{url}}"
      ],
      "path": [
        "indexes",
        "{{indexUID}}",
        "settings",
        "ranking-rules"
      ]
    }
  },
  "response": [
  ]
}