Ich versuche API-Gateway SDK hinzuzufügen Code reagieren zu können, aber ich bin neu in ES6 und reagieren, so ist es schwer, einen WegWie API API Gateway SDK zum Reagieren hinzufügen?
Dies ist meine Reaktion Projektstruktur zu finden:
myReactProject
- node_modules
- src
-- components
---- ApigClient
------ lib (AWS APIGateway JS files)
------ apigClient.js
------ ApigValidation.js
---- otherComponents..
---- index.js
-- containers
---- App
------ App.js
------ App.scss
---- Home
------ Home.js
------ Home.scss
---- OtherContainerFiles
---- index.js
-- redux
-- utils
---- validation.js
-- client.js
-- config.js
-- routes.js
-- server.js
Und ich habe versucht, das API-Gateway SDK auf 2 Arten zu importieren:
1)
import ApigClient from './ApigClient';
import apiGatewayClient from './lib/apiGatewayCore/apiGatewayClient'
import sigV4ClientConfig from './lib/apiGatewayCore/sigV4ClientConfig'
import simpleHttpClientConfig from './lib/apiGatewayCore/simpleHttpClientConfig'
import utils from './lib/apiGatewayCore/utils'
import enc-base64 from './lib/CryptoJS/component/enc-base64'
import hmac from './lib/CryptoJS/component/hmac'
import hmac-sha256 from './lib/CryptoJS/rollups/hmac-sha256'
import sha256 from './lib/CryptoJS/rollups/sha256'
import axios from './lib/axios/dist/axios.standalone'
import url-template from './lib/url-template/url-template'
2)
class ApigValidation extends Component {
render() {
return (
<div>
<h1>Hello</h1>
<script type="text/javascript" src="./lib/axios/dist/axios.standalone.js"></script>
<script type="text/javascript" src="./lib/CryptoJS/rollups/hmac-sha256.js"></script>
<script type="text/javascript" src="./lib/CryptoJS/rollups/sha256.js"></script>
<script type="text/javascript" src="./lib/CryptoJS/components/hmac.js"></script>
<script type="text/javascript" src="./lib/CryptoJS/components/enc-base64.js"></script>
<script type="text/javascript" src="./lib/url-template/url-template.js"></script>
<script type="text/javascript" src="./lib/apiGatewayCore/sigV4Client.js"></script>
<script type="text/javascript" src="./lib/apiGatewayCore/apiGatewayClient.js"></script>
<script type="text/javascript" src="./lib/apiGatewayCore/simpleHttpClient.js"></script>
<script type="text/javascript" src="./lib/apiGatewayCore/utils.js"></script>
<script type="text/javascript" src="apigClient.js"></script>
<script type="text/javascript">
var apigClient = apigCleint.newClient({
apiKey: 'This-is-my-api-key'
});
apigClient.myFuncGet(params, null)
.then(function(response) {
console.log(JSON.stringify(response));
}).catch(function(resuponse) {
console.log(JSON.stringify(response));
});
</script>
</div>
);
}
}
1) Ist die Ordnerstruktur richtig? Soll ich SDK in Utils setzen?
2) Wie kann ich JS SDK importieren/laden/hinzufügen in reagieren und aktivieren Sie Get/Post-Funktion?
Bitte beraten, hochachtungsvoll geschätzt!
Verwenden Sie https://github.com/erikras/react-redux-universal-hot-example als Basis? – markthethomas
@markthethomas Ja! Genau. Dies zu sagen, würde den Lesern helfen zu verstehen. Danke! – Donna
Kein Problem! Siehe meine Antwort unten für die Optionen. Mit diesem Starter sollte es so einfach sein wie erfordert es und konfigurieren mit einem API-Schlüssel – markthethomas