Sample code for 30+ languages & platforms
Rust

SCIS Search

See more SCiS Schools Catalogue Examples

Demonstrates the SCIS (Schools Catalogue Information Service) search API call.

Chilkat Rust Downloads

Rust

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

let http = chilkat::Http::new();

// Implements the following CURL command:

// curl -i -X GET --url 'https://api.scisdata.com/catalogue/api/search?query=titleSearch%3Adogs%20AND%20publicationYear%3A2015&from=0&size=20&sort=author&order=asc' -H 'Authorization: Basic ****'

// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code

// This causes the "Authorization: Basic ****" to be added to each request.
http.set_login("myLogin");
http.set_password("myPassword");
http.set_basic_auth(true);

let sb_query = chilkat::StringBuilder::new();
let _ = sb_query.append("titleSearch:dogs AND publicationYear:2015");

let sb_url = chilkat::StringBuilder::new();
let _ = sb_url.append("https://api.scisdata.com/catalogue/api/search?query=");
// If non-usascii chars are included in the search, we don't know if utf-8 or windows-1252 is desired by the server.  You'll need to find out..
let _ = sb_url.append(&sb_query.get_encoded("url", "utf-8").unwrap_or_default());
let _ = sb_url.append("&from=0&size=20&sort=author&order=asc");

let sb_response_body = chilkat::StringBuilder::new();
if http.quick_get_sb(&sb_url.get_as_string().unwrap_or_default(), &sb_response_body).is_err() {
    println!("{}", http.last_error_text());
    return;
}

let j_resp = chilkat::JsonObject::new();
let _ = j_resp.load_sb(&sb_response_body);
j_resp.set_emit_compact(false);

println!("Response Body:");
println!("{}", j_resp.emit().unwrap_or_default());

let resp_status_code = http.last_status();
println!("Response Status Code = {}", resp_status_code);
if resp_status_code >= 400 {
    println!("Response Header:");
    println!("{}", http.last_header());
    println!("Failed.");
    return;
}

// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)

// {
//   "data": {
//     "hits": {
//       "hits": [
//         {
//           "_index": "scisdata2",
//           "_type": "bibdatatype",
//           "_source": {
//             "isbn": [
//               "9781517638160"
//             ],
//             "languageTermCode": [
//               "eng"
//             ],
//             "mainAuthor": {
//               "namePersonalPrimary": [
//                 "Abbott, Eleanor Hallowell."
//               ]
//             },
//             "title": {
//               "titlePrimary": [
//                 "Peace on Earth, good-will to dogs"
//               ],
//               "noteStmOfResponsibility": [
//                 "by Eleanor Hallowell Abbott."
//               ]
//             },
//             "scisType": [
//               "Book"
//             ],
//             "dateIssuedMarc": 2015,
//             "languageTermValue": [
//               "English"
//             ],
//             "contributor": {},
//             "isbn13": "9781517638160",
//             "imageFileName": "9781517638160.jpg",
//             "publicationDetails": "United States, Create Space Independent Publishing Platform, 2015",
//             "isbn10": "151763816X",
//             "id": "1867852"
//           },
//           "_id": "1867852",
//           "sort": [
//             "abbott, eleanor hallowell."
//           ],
//           "_score": null
//         },
//         {
//           "_index": "scisdata2",
//           "_type": "bibdatatype",
//           "_source": {
//             "isbn": [
//               "9781780747910"
//             ],
//             "languageTermCode": [
//               "eng"
//             ],
//             "mainAuthor": {
//               "namePersonalPrimary": [
//                 "Adams, Richard."
//               ]
//             },
//             "title": {
//               "titlePrimary": [
//                 "The plague dogs"
//               ],
//               "noteStmOfResponsibility": [
//                 "Richard Adams."
//               ]
//             },
//             "scisType": [
//               "Book"
//             ],
//             "dateIssuedMarc": 2015,
//             "languageTermValue": [
//               "English"
//             ],
//             "contributor": {},
//             "isbn13": "9781780747910",
//             "imageFileName": "9781780747910.jpg",
//             "publicationDetails": "New York, Rock the Boat, 2015",
//             "isbn10": "1780747918",
//             "id": "1749228"
//           },
//           "_id": "1749228",
//           "sort": [
//             "adams, richard."
//           ],
//           "_score": null
//         },
//          ...
//       ],
//       "total": 84,
//       "max_score": null
//     },
//     "took": 585,
//     "timed_out": false
//   },
//   "subscriptionStatus": {}
// }

// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON

let mut j: i32 = 0;
let mut count_j: i32 = 0;

let data_hits_total = j_resp.int_of("data.hits.total");
let data_hits_max_score = j_resp.string_of("data.hits.max_score").unwrap_or_default();
let data_took = j_resp.int_of("data.took");
let data_timed_out = j_resp.bool_of("data.timed_out");
let mut i = 0;
let count_i = j_resp.size_of_array("data.hits.hits");
while i < count_i {
    j_resp.set_i(i);
    let _ = j_resp.string_of("data.hits.hits[i]._index").unwrap_or_default();
    let _ = j_resp.string_of("data.hits.hits[i]._type").unwrap_or_default();
    let _ = j_resp.int_of("data.hits.hits[i]._source.dateIssuedMarc");
    let _ = j_resp.string_of("data.hits.hits[i]._source.isbn13").unwrap_or_default();
    let _ = j_resp.string_of("data.hits.hits[i]._source.imageFileName").unwrap_or_default();
    let _ = j_resp.string_of("data.hits.hits[i]._source.publicationDetails").unwrap_or_default();
    let _ = j_resp.string_of("data.hits.hits[i]._source.isbn10").unwrap_or_default();
    let _ = j_resp.string_of("data.hits.hits[i]._source.id").unwrap_or_default();
    let _ = j_resp.string_of("data.hits.hits[i]._id").unwrap_or_default();
    let _ = j_resp.string_of("data.hits.hits[i]._score").unwrap_or_default();
    j = 0;
    count_j = j_resp.size_of_array("data.hits.hits[i]._source.isbn");
    while j < count_j {
        j_resp.set_j(j);
        let _ = j_resp.string_of("data.hits.hits[i]._source.isbn[j]").unwrap_or_default();
        j = j + 1;
    }

    j = 0;
    count_j = j_resp.size_of_array("data.hits.hits[i]._source.languageTermCode");
    while j < count_j {
        j_resp.set_j(j);
        let _ = j_resp.string_of("data.hits.hits[i]._source.languageTermCode[j]").unwrap_or_default();
        j = j + 1;
    }

    j = 0;
    count_j = j_resp.size_of_array("data.hits.hits[i]._source.mainAuthor.namePersonalPrimary");
    while j < count_j {
        j_resp.set_j(j);
        let _ = j_resp.string_of("data.hits.hits[i]._source.mainAuthor.namePersonalPrimary[j]").unwrap_or_default();
        j = j + 1;
    }

    j = 0;
    count_j = j_resp.size_of_array("data.hits.hits[i]._source.title.titlePrimary");
    while j < count_j {
        j_resp.set_j(j);
        let _ = j_resp.string_of("data.hits.hits[i]._source.title.titlePrimary[j]").unwrap_or_default();
        j = j + 1;
    }

    j = 0;
    count_j = j_resp.size_of_array("data.hits.hits[i]._source.title.noteStmOfResponsibility");
    while j < count_j {
        j_resp.set_j(j);
        let _ = j_resp.string_of("data.hits.hits[i]._source.title.noteStmOfResponsibility[j]").unwrap_or_default();
        j = j + 1;
    }

    j = 0;
    count_j = j_resp.size_of_array("data.hits.hits[i]._source.scisType");
    while j < count_j {
        j_resp.set_j(j);
        let _ = j_resp.string_of("data.hits.hits[i]._source.scisType[j]").unwrap_or_default();
        j = j + 1;
    }

    j = 0;
    count_j = j_resp.size_of_array("data.hits.hits[i]._source.languageTermValue");
    while j < count_j {
        j_resp.set_j(j);
        let _ = j_resp.string_of("data.hits.hits[i]._source.languageTermValue[j]").unwrap_or_default();
        j = j + 1;
    }

    j = 0;
    count_j = j_resp.size_of_array("data.hits.hits[i].sort");
    while j < count_j {
        j_resp.set_j(j);
        let _ = j_resp.string_of("data.hits.hits[i].sort[j]").unwrap_or_default();
        j = j + 1;
    }

    j = 0;
    count_j = j_resp.size_of_array("data.hits.hits[i]._source.contributor.namePersonalOther");
    while j < count_j {
        j_resp.set_j(j);
        let _ = j_resp.string_of("data.hits.hits[i]._source.contributor.namePersonalOther[j]").unwrap_or_default();
        j = j + 1;
    }

    j = 0;
    count_j = j_resp.size_of_array("data.hits.hits[i]._source.contributor.nameCorporateOther");
    while j < count_j {
        j_resp.set_j(j);
        let _ = j_resp.string_of("data.hits.hits[i]._source.contributor.nameCorporateOther[j]").unwrap_or_default();
        j = j + 1;
    }

    i = i + 1;
}