Application Programming Interface Flashcards

1
Q

API

A

Interface layer to interact with an external system.

The interactions are via the form of GET and POST requests

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Using the Request Module to Get Data from an API

A
request - NPM module
Setup
const request = require(“request”);
Usage
request.(, );

function(error, response, body);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Understanding the JSON format and Working with JSON

JSON

A
JavaScript Object Notation
Used to communicate data back and forth in the web
XML [eXtensive Markup Language] 
Alternative to JSON, came before JSON.
Less frequently used now
JavaScript object -> string
JSON.stringify();
string -> JavaScript Object
JSON.parse();
Sending more than one thing
res.write();
res.send();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

API Calls with Parameters

A

Please see the following screenshot

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Newsletter Walkthrough

A

Incorporated and modified an existing Bootstrap Sign In Example
In the HTML, some files are directly obtained from the internet via the use of the web urls
However, some are static files such as css and images files.
In order to use them, we must notify Express that they are static
To do this, we can create a folder where all the static files will be contained,
And then call the express.static()

In the form, be sure to specify action and method
So the picture above, the form will POST to the location in action

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Posting Data to Mailchimp Servers

A

Set up MailChimp Account & Obtain API Key
Set up the request url and headers
Authentication
Look through the API documentation on authentication

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Adding Success/Failure Pages to the Website

A

Instead of sending text back upon success or failure. We now send back an individual html file
Redirecting back to a specific page
Method: Create a button, when pressed it will create a post request.
In the server, handle the post request to the location, by redirecting to the intended page

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Deploy the project to Heroku and Make it Live

//

What is Heroku?

A

Heroku allows users to deploy their websites on Heroku’s servers, so that anyone can access the website.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

To use Heroku:

A
  1. Modify the prior app.listen(3000, ); to app.listen(process.env.PORT || 3000, );

process.env.PORT - Heroku will handle the setting of the port
|| 3000 - This will be used in the case that Heroku is not being used
2. Define a Procfile
Create a file named Procfile that is in the same folder as the main root of the website
Inside, write the same command as you would write in the terminal to execute your website
web: node app.js
3. Initialize and Commit the web project using git
In the web project root directory, execute git init
Add the files, git add .
Commit the files, git commit -m “Commit message”
4. Create a Heroku Reference to your Web Project, Git
Execute, heroku create
By default, heroku creates a random name to your project
But you can pass a parameter to set the name
Execute, git push heroku master
Web project is now deployed on Heroku
5. Running the web site on Heroku
1. Can run heroku open on the root directory of the web project
2. Can run the heroku url given after heroku create

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Checking Heroku logs

A

Run heroku logs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly