The API you built in Task 6
The DynamoDB table we created in Task 3
cURL and/or Postman for API testing
- With the 'ALX402FactAPI' selected
- Click on the 'Actions' dropdown
- Click on 'Enable CORS'
- Click the blue 'Enable CORS button and replace existing CORS headers'
- Click the blue 'Yes confirm existing values' button
- Click on the 'Actions' dropdown again
- Click on 'Deploy API'
- Select '[New Stage]' from 'Deployment stage'
- Type
Test
into the 'Stage name' Field - You can fill the other two fields if you want
- Click blue 'Deploy' button
-
Copy the 'Invoke URL' from the 'Stage Editor' screen & save it to a text file
-
Use Postman to test (or skip to step 12 and use cURL)
- Open Postman
- Start with a New tab
- Select 'Post' from the dropdown
- Paste the 'Invoke URL' you copied into the 'Request URL' field
- Click on 'Headers'
- Type 'Content-Type' under 'Key' & 'application/json' under 'Value'
- Click on 'Body'
- Select the 'Raw' radio button
- Copy and paste the following object into the field
{ "locale": "en-US", "speech": "From Postman", "text": "Text from Postman" }
- Click 'Send'
- The status for the response should be '200'
- The body for the response should be '{}'
- There should be a new item in your DynamoDB table
-
Use cURL to test (not necessary if you tested with potman in step 11)
- Open a Terminal or Command Line window
- Use the following command
curl -d '{"locale": "en-US", "speech":"From cURL", "text": "Text from cURL"}' -H 'Content-Type: application/json' https://yourInvocatiourl
- You should get '{}' as a response
- There should be a new item in your DynamoDB table
- Navigate to the S3 console using the Service search bar
- Click the blue 'Create bucket' button
- Give your bucket a unique name
- All S3 buckets share the same namespace
- Cannot contain capital letters
- Select 'EU (Ireland)' as the 'Region'
- Don't copy the settings from another bucket
- Click the white 'Create' button
- Click on your recently created bucket name
- Click on the 'Properties' tab from the top navigation bar
- Click on the 'Static website hosting' box
- Select the radio button for 'Use this bucket to host a website'
- Type
index.html
&error.html
in the corresponding fields - Leave 'Redirection rules' blank
- Click the blue 'Save' button
- You'll see a purple check mark in the 'Static website hosting' box
- Scroll the back to the top
- Click on the 'Overview' tab
- Open a new file in a text editor and paste the following html/javascript code
<!doctype html>
<head>
<meta charset="utf-8">
<title>Index</title>
</head>
<body>
<h3>Simple web page for capturing facts</h3>
<script type="text/javascript">
let localeInput = prompt("Input a locale for the fact", "en-US");
let speechInput = prompt("Input fact to be spoken", "<say-as interpret-as='interjection'>abracadabra!</say-as>, a fact added from web page");
let textInput = prompt("Input text for the fact", "a fact added from web page");
let data = JSON.stringify({
"locale": localeInput,
"speech": speechInput,
"text": textInput
});
let xhr = new XMLHttpRequest();
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://<YourAPIURLhere>");
xhr.setRequestHeader("content-type", "application/json");
xhr.send(data);
console.log(xhr.responseText);
</script>
</body>
- Save the file as
index.html
- In the file you just created
- change the URL to the invoke URL for your API, you copied it in Task 7 step 9
- Click the blue 'Upload' button
- Click the blue 'Add Files' button
- Select the index.html file you created in step 13
- Click 'Open'
- Confirm you selected the correct file & click the blue 'Upload' button
- Click on the index.html on the file that was uploaded
- Click the white 'Make public' button
- A 'Success' dialog message will be displayed
- At the bottom of the page there will be a link to the file hosted on S3, click on it
- You should be presented with the web page we created
- Fill the three prompts that will be presented
- We pre-filled this for you convenience, but feel free to get creative
- Navigate to the DynamoDB table and make sure a new fact matching your input was stored
- Look at the logs for the web page using your browsers developer tools
- There should be a single line for the response : '{}'