This page presents an example of using the ThrustCurve API to find motors and download data for them. See the API documentation page for high-level info; this page contains a specific example app.
This demo uses the metadata, search and download API endpoints through JSON directly in the browser. The API also supports XML, but JSON will be more commonly used for web mashups.
You may also like to explore the API through SwaggerHub.
These demos assume JQuery, but any other way of issuing requests will work just fine. Note that the API doesn't require being called from a browser nor does it require any headers to be sent.
We want to create a search form, but need to know how to populate the select inputs. The natural way to get that info is through the metadata API. We'll access this through a GET method since we don't need to provide inputs. Try it out by pressing the "Metadata" button below.
// use GET to download metadata for all motors
$.get('https://www.thrustcurve.org/api/v1/metadata.json', function(data) {
console.log('metadata response:', data);
// populate the combo boxes in the search form
let form = $('form[name=search]');
let select = form.find('select[name=manufacturer]');
select.empty().append($('<option selected>(all)</option>'));
data.manufacturers.forEach(mfr => {
select.append($(`<option value="${mfr.abbrev}">${mfr.name}</option>`));
});
select = form.find('select[name=diameter]');
select.empty().append($('<option selected>(all)</option>'));
data.diameters.forEach(diam => {
select.append($(`<option>${diam}</option>`));
});
select = form.find('select[name=impulseClass]');
select.empty().append($('<option selected>(all)</option>'));
data.impulseClasses.forEach(cls => {
select.append($(`<option>${cls}</option>`));
});
});
The combo boxes of this form get populated by the code above. Make sure to run it at least once by pressing the "Metadata" button above. Then choose some combination of search criteria and press the "Search" button below.
The execute the search API, we use the POST method supplying the search criteria as a JSON object.
// pick up criteria from the form above
let form = $('form[name=search]');
let req = {};
['commonName', 'manufacturer', 'diameter', 'impulseClass'].forEach(prop => {
let v = form.find(':input[name=' + prop + ']').val();
if (v != null && v.trim() !== '' && v !== '(all)')
req[prop] = v;
});
console.log('search request:', req);
// use POST with the criteria as the JSON body
$.ajax({
url: 'https://www.thrustcurve.org/api/v1/search.json',
method: 'POST',
data: JSON.stringify(req),
success: function(data) {
console.log('search response:', data);
// put key data for each motor into the table
let motors = $('table.motors tbody');
motors.empty();
function num(v, d) {
return v > 0 ? v.toFixed(d) : "";
}
let summary = data.criteria.length < 1 ? 'no' : data.criteria.length;
summary += ' search criteria: ';
if (data.results != null && data.results.length > 0) {
data.results.forEach(r => {
let tr = $(`<tr>
<td><input type="radio" name="motorId" value="${r.motorId}"></td>
<td>${r.manufacturerAbbrev}</td>
<td>${r.designation}</td>
<td>${r.diameter}</td>
<td>${num(r.totImpulseNs, 1)}</td>
<td>${num(r.burnTimeS, 2)}</td>
<td>${r.dataFiles}</td>
</tr>`);
motors.append(tr);
});
if (data.results.length == data.matches)
summary += `all ${data.results.length} matches`;
else
summary += `${data.results.length} of ${data.matches} matches`;
} else {
summary += 'no matches';
}
$('table.motors tfoot td').text(summary);
},
});
This table gets populated by the search form above. Once you've executed a search that matches existing motors, click on one of the radio buttons in the first column to choose that motor and press the "Download" button below.