32. <aura:component
implements="flexipage:availableForAllPageTypes,lightning:availableFo
rFlowActions,lightning:availableForFlowScreens">
<aura:attribute name="jsonArray" type="Object[]"/>
<aura:handler name="init" value="{!this}" action="{!c.invoke}" />
<table class="slds-table slds-table--bordered">
<tbody>
<aura:iteration items="{!v.jsonArray}" var="row">
<tr>
<td> {!row.id}</td>
<td> {!row.name}</td>
<td> {!row.type}</td>
</tr>
</aura:iteration>
</tbody>
</table>
</aura:component>
({
invoke : function(component, event, helper) {
var args = event.getParam("arguments");
return new Promise(function(resolve, reject) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = $A.getCallback(function() {
if (this.readyState === 4) { // DONE
if (this.status >= 200 && this.status < 300) {
var response = JSON.parse(xhttp.responseText);
component.set("v.jsonArray", response);
resolve();
} else {
var errorText = "";
if (this.status === 0) {errorText = 'Request has been terminatednPossible causes: the network is
offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.’;}
else {errorText = this.statusText;}
reject(new Error("ERROR"));}
}
});
xhttp.open("GET", "https://immense-cove-13692.herokuapp.com/api/order/list", true);
xhttp.send(null);
});
}
})
33. • Lightning
• CSP URL
• Web CORS (Cross-Origin
Resource Sharing)
// API
app.get("/api/order/list", function(req, res, next){
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-
Requested-With');
res.json(orderList);
});
Node.js CORS
34. Lightning
Swagger / Open API 2.0 REST
GA
[Swagger/Open API ]
RESTful API
JSON/YAML
REST
①● Interagent
● Swagger/Open API
2.0
②
API
③ APEX
35. [ ] Swagger / Open API
• RESTful API API
Open API Initiative OSS
API
https://swagger.io
https://www.openapis.org
• Swagger / Open API
API API API
API