Skip to content

Commit 7c9b42c

Browse files
JAMES NEIMAN CONSULTINGJAMES NEIMAN CONSULTING
authored andcommitted
edits
1 parent e319b02 commit 7c9b42c

File tree

52 files changed

+1219
-1254
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1219
-1254
lines changed

.DS_Store

-8 KB
Binary file not shown.

labs/.DS_Store

-8 KB
Binary file not shown.

labs/coding-101-rest-basics-ga/1.md

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,43 @@
11

22
# Coding 101 - REST API Basics with APIC-EM
33

4-
This Learning Lab explains the basics of using a REST API, and how to use POSTMAN to explore a REST API.
4+
This Learning Lab explains the basics of using a REST API. It also shows how to use Postman to explore a REST API.
55

66
## Objective
77

88
* Understand REST APIs
9-
* Learn how to use the POSTMAN application to make API calls
10-
9+
* Learn how to use the Postman application to make API calls
1110

1211
## Prerequisites
1312

14-
- <a href="https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en" target="_blank">POSTMAN</a> installed.
15-
If you are on a DevNet Zone station, <a href="https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en" target="_blank">POSTMAN</a> is already installed. You can start it from the Google App Launcher or from Chrome by clicking <a href="https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en" target="_blank">here</a> and clicking on **Launch App**.
13+
- <a href="https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en" target="_blank">Postman</a> installed.
14+
If you are on a DevNet Zone station, <a href="https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en" target="_blank">Postman</a> is already installed. You can start it from the Google App Launcher or Chrome by clicking <a href="https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en" target="_blank">here</a> and clicking **Launch App**.
1615

17-
- Access to an APIC-EM Controller. To run the code samples, you need access to an APIC-EM controller. If you are not using your own APIC-EM controller, you can use the Always-On APIC-EM Lab:
16+
- Access to an APIC-EM Controller. To run the code samples, you need access to an APIC-EM controller. If you are not using your APIC-EM controller, you can use the APIC-EM Lab:
1817
* https://sandboxapicem.cisco.com
19-
* **username:** devnetuser
18+
* **username:** devnetuser
2019
* **password:** Cisco123!
2120

2221
## Step 1. Find the APIC-EM API Resources and Documentation
2322

24-
A good starting point to understand any API is to look at the documentation for the API. Let's find documentation for the APIC-EM API.
23+
A good starting point to understand any API is to look at the documentation for the API. Now, find documentation for the APIC-EM API.
2524

2625
1. In a browser, navigate to the <a href="https://developer.cisco.com" target="_blank">DevNet</a> home page.
27-
2. Click the **Login** link located on the top right of the web page.
26+
2. Click the **Login** link located at the top right of the webpage.
2827
![](/posts/files/coding-101-rest-basics-ga/assets/images/login.png)<br/><br/>
2928
3. On the Log In page, enter your credentials.
30-
If you want to log in with a Cisco ID but do not have a Cisco Connection Online ID (CCO ID) click the **Register Now** button and follow the instructions. Then, return to the Log In web page and enter your credentials.
29+
To log in with a Cisco ID but do not have a Cisco Connection Online ID (CCO ID) click the **Register Now** button and follow the instructions. Then, return to the Log In webpage and enter your credentials.
3130
<br/><br/>
3231
4. Use the menu at the top to navigate to the APIC-EM web portal.
33-
* Click the **Technologies** link to see the submenu.
34-
* Click on **Networking**
35-
* From the list of technologies, click on **APIC Enterprise Module (APIC-EM)**<br/>The APIC-EM web page appears.
32+
* Click the **Technologies** link to see the submenu.
33+
* Click **Networking**
34+
* From the list of technologies, click **APIC Enterprise Module (APIC-EM)**<br/>The APIC-EM webpage appears.
3635
![](/posts/files/coding-101-rest-basics-ga/assets/images/Menu.png)
3736
<br/>
38-
5. On the APIC-EM web page. Click the `Docs` link.<br/>
37+
5. On the APIC-EM webpage. Click the `Docs` link.<br/>
3938
![](/posts/files/coding-101-rest-basics-ga/assets/images/apic-em-main.png)
4039
6. Select the latest API version.
41-
7. Keep the APIC-EM API Reference documentation open in a separate tab. This will be a useful reference while you work on this lab.
40+
7. Keep the APIC-EM API Reference documentation open in a separate tab. This will be a useful reference while you work on this lab.
4241
![](/posts/files/coding-101-rest-basics-ga/assets/images/Ref.png)
4342
<br/>
4443
<br/>

labs/coding-101-rest-basics-ga/2.md

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,41 @@
33
### What is a Web Service?
44

55
A web service is a way for two systems to communicate through a defined interface.
6-
There are two major types of web services – **REST** or **SOAP**.
6+
There are two major types of web services – **REST** and **SOAP**.
77

88
### What is a *REST* Web Service?
99

1010
REST is an architecture style for designing networked applications.
1111
A REST web service is as easy to call as making an HTTP request.
12-
RESTful interfaces often offer the CRUD (Create, Update, Delete) operations.
13-
If you want to know more about REST in general, this is a great <a href="http://rest.elkstein.org" target="_blank">REST tutorial</a>.
12+
RESTful interfaces usually offer the CRUD (Create, Update, Delete) operations.
13+
To know more about REST in general, this is a great <a href="http://rest.elkstein.org" target="_blank">REST tutorial</a>.
1414

1515

16-
### What are the benefits of REST?
16+
### What are the benefits of REST?
1717

1818
***REST is easy to use on any platform***
1919

2020
![](/posts/files/coding-101-rest-basics-ga/assets/images/RESTisGreat.jpg)
2121

2222
### APIC-EM API is a REST API
2323

24-
For this lab, we are going to use the <a href="https://developer.cisco.com/site/apic-em/" target="_blank">APIC-EM APIs</a>.
24+
For this lab, you are going to use the <a href="https://developer.cisco.com/site/apic-em/" target="_blank">APIC-EM APIs</a>.
2525

26-
The Application Policy Infrastructure Control (APIC) Enterprise Module (EM), Application Programming Interface (API), <a href="https://developer.cisco.com/site/apic-em/" target="_blank">APIC-EM APIs</a>, allows the deployment and execution of application policy across your networking infrastructure.
26+
The Application Policy Infrastructure Control (APIC) Enterprise Module (EM), Application Programming Interface (API), <a href="https://developer.cisco.com/site/apic-em/" target="_blank">APIC-EM APIs</a>, enables deploying and running application policies across your networking infrastructure.
2727

28-
Using the APIC-EM APIs, we can retrieve information about devices on our network including a list of hosts, network devices, or users. We are going to use these features as examples to learn how to make REST calls from Python.
28+
Using the APIC-EM APIs, you can retrieve information about devices on your network including a list of hosts, network devices, or users. You are going to use these features as examples to learn how to make REST calls from Python.
2929

30-
Take a look at the <a href="http://devnetapic.cisco.com/" target="_blank">APIC-EM Reference Docs</a> to see the details of all of the APIC-EM functions.
30+
Look at the <a href="http://devnetapic.cisco.com/" target="_blank">APIC-EM Reference Docs</a> to see the details of the APIC-EM functions.
3131

3232

3333
### How does this work?
3434

3535
![](/posts/files/coding-101-rest-basics-ga/assets/images/howitworks.jpg "How it Works")
3636

37-
REST is centered around the HTTP request and response model. Consuming an API is just as simple as making an HTTP request.
37+
REST is centered around the HTTP request and response model. Consuming an API is as simple as making an HTTP request.
3838

39-
In this example, we request the list of hosts, and that information is returned to us in the response. The data returned in the response is usually formatted as json or xml.
39+
In this example, you request the list of hosts, and that information is returned to you in the response. The data returned in the response is usually formatted as JSON or XML.
4040

4141
(<a href="http://www.json.org/" target="_blank">JSON</a> -- JavaScript Object Notation, is a lightweight text-based open standard designed for human-readable data interchange.)
4242

43-
<br/>
44-
<br/>
45-
4643
### Next Step: HTTP Response Request Facts

labs/coding-101-rest-basics-ga/3.md

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,40 @@
11
## Step 3. What do I need to know to make a Request?
22

3-
To construct a request, you need to know the following information for the API that you are calling. You can find this information in the API reference documentation.
3+
To construct a request, determine the following information for the API that you are calling. You can find this information in the API reference documentation.
44

55
- **Method**
6+
Choose one of the following http methods:
67
* GET - Retrieve data
78
* POST - Create something new
89
* PUT - Update data
910
* DELETE - Delete data
1011

1112
- **URL**
12-
* The URL for the endpoint you want to call
13+
* Determine the URL of the endpoint you want to call.
1314
* Example: `http://{APIC-EMController}/api/v1/ticket`
14-
* Where `{APIC-EMController}` is the controller IP or hostname
15-
* If you are not using your own APIC-EM controller, use the Always-On APIC-EM Lab: ![https://devnetapi.cisco.com/sandbox/apic_em]() .
15+
* Where `{APIC-EMController}` is the controller IP or hostname.
16+
* Use the Cisco DevNet Learning Lab's APIC-EM controller, at https://devnetapi.cisco.com/sandbox/apic_em, or enter the URL/IP address of an APIC-EM controller on your network.
1617
- **URL Parameters**
17-
* The parameters that you can pass as part of the URL.
18+
* If the endpoint requires URL parameters, pass them as part of the URL. To get this information, refer to the reference documentation for the particular endpoint.
1819
- **Authentication**
19-
* You need to know the authentication type to use. Basic HTTP, token-based, and OAuth are common types.
20-
* Authentication credentials
20+
* Determine which authentication type to use. Basic HTTP, token-based, and OAuth are common types.
21+
* Add the authentication credentials to the API call you are preparing.
2122
- **Custom Headers**
22-
* Does the API require you to send any HTTP Headers?
23-
* Example: Content-Type: application/json
23+
* If required, add any HTTP Headers to the API call you are preparing. For example: `Content-Type: application/json`.
2424
- **Request Body**
25-
* JSON or XML containing data that is needed to complete request can be sent in the body of the request
25+
* If required, include a JSON- or XML-formatted request body that contains any data that is needed.
2626

27-
### A Little About Authentication
27+
### About Authentication
2828

29-
There are three common types of authentication for REST APIs. Authentication is used to control access and access rights to the REST APIs. For example, some users might have read-only access which means that they can make only API endpoints that read data. Other users might be allowed to both read and change (add, edit, delete) data, meaning they can call any of the API endpoints. These access rights are typically-based upon assigned user roles such as *Administrator*, which grants a user full rights to change data, and *User*, which grants read-only access.
29+
Authentication controls whether a user user can access a specific API endpoint and how they can it. For example, one user might have read-only privileges, which they can only make API calls that read data. Another user might have read and change (add, edit, delete) privileges to every endpoint, which means they can make any API call. These access rights are typically-based upon assigned user roles such as *Administrator*, which grants a user full rights to change data, and *User*, which grants read-only access.
3030

31-
1. **Basic HTTP:** The username and password are passed to the server in an encoded string. For more information, see [Basic Authentication](https://en.wikipedia.org/wiki/Basic_access_authentication).
32-
2. **OAuth:** Open standard for HTTP authentication and session management. Creates an access token associated with a specific user that also specifies the user rights. The token is used to identify the user and rights when making API calls to verify access and control. See [OAuth](https://en.wikipedia.org/wiki/OAuth) for more information.
31+
REST APIs have three common methods to authenticate users:
32+
33+
* **Basic HTTP:** The username and password are passed to the server as an encoded string. For more information, see [Basic Authentication](https://en.wikipedia.org/wiki/Basic_access_authentication).
34+
* **OAuth:** Open standard for HTTP authentication and session management. Creates an access token associated with a specific user that also specifies the user rights. The token identifies the user and rights when making API calls to verify access and control. See [OAuth](https://en.wikipedia.org/wiki/OAuth) for more information.
3335
3. **Token:** As with OAuth, a token is created and passed with each API call, but there is no session management and tracking of clients. This simplifies interaction between the server and client. APIC-EM uses this design for authentication management. See [Token Based Authentication](https://scotch.io/tutorials/the-ins-and-outs-of-token-based-authentication) for more information.
3436

35-
APIC-EM uses token-based authentication. So the first request we need to make creates a token. In APIC-EM, this token is called a *service ticket*. The controller uses the service ticket to determine which endpoints you can access. The service ticket must be included in every API call except the one that creates the ticket.
37+
APIC-EM uses token-based authentication. So the first request you need to make creates a token. In APIC-EM, this token is called a *service ticket*. The controller uses the service ticket to determine which endpoints you can access. The service ticket must be included in every API call except the one that creates the ticket.
3638

3739
The steps for using the APIC-EM authentication token are:
3840

@@ -42,45 +44,40 @@ The steps for using the APIC-EM authentication token are:
4244

4345
### Using the API Reference Documentation
4446

45-
The API Reference Documentation is where you can find the list of all of the API methods and the details for how to make each request. When you are starting to work with a new API,
47+
The API Reference Documentation is where you can find the list of the API methods and the details for information on how to make each request. When you are starting to work with a new API,
4648
the API Reference is one of the most important sources of information.
4749

48-
Let's take a look at the Ticket API in APIC-EM.
50+
Study the Ticket API in APIC-EM:
4951

50-
* Open the <a href="http://devnetapic.cisco.com/" target="_blank">APIC-EM Reference Docs</a> The entire API is presented in scrollable format.
52+
* Open the <a href="http://devnetapic.cisco.com/" target="_blank">APIC-EM Reference Docs</a>. The entire API is presented in scrollable format.
5153

5254
![](/posts/files/coding-101-rest-basics-ga/assets/images/refguide1.png)
5355

5456
* Click **Roll Based Access Control**, then click **ticket**.
5557

5658
![](/posts/files/coding-101-rest-basics-ga/assets/images/refguide2.png)
5759

58-
* On ticket, click **'POST' /ticket**. This endpoint provides functionality to create a ticket.
60+
* Click **'POST' /ticket**. This endpoint provides functionality to create a ticket.
5961
![](/posts/files/coding-101-rest-basics-ga/assets/images/refguide3.png)
6062

61-
### What is in the Response?
62-
63-
The API Reference includes information data attributes to be sent and returned. The returned data is defined in the Response portion which includes the HTTP status codes along with the data format and attributes to be returned.
63+
* The API Reference includes attributes to be sent and returned. The Response portion defines the returned data, including HTTP status codes.
6464

65-
* HTTP Status Codes
66-
* HTTP status codes are used to return success, error, or other statuses. [http://www.w3.org/Protocols/HTTP/HTRESP.html](http://www.w3.org/Protocols/HTTP/HTRESP.html)
67-
* Some common examples are:
65+
* HTTP status codes indicate success, error, or other conditions. For more information, see [http://www.w3.org/Protocols/HTTP/HTRESP.html](http://www.w3.org/Protocols/HTTP/HTRESP.html)
66+
Some common codes are:
6867
* 200 OK
6968
* 202 Accepted/Processing
7069
* 401 Not Authorized
7170

7271

73-
* Review the content to see what data is expected to be sent to the server and returned to your application. Both are circled here. In the example response for the Create Ticket request, we can see that the response string contains a "serviceTicket" attribute with a value of type string. This is the token value that is needed to make api calls for all of the other API endpoints.
72+
* Review the content to see what data is expected to be sent to the server and returned to your application. Both are circled here. In the example response for the Create Ticket request, you can see that the response string contains a `serviceTicket` attribute with a value of type string. This value is the authentication token you will need to make calls to all of the other API endpoints.
7473

7574
![](/posts/files/coding-101-rest-basics-ga/assets/images/refguide4.png)
7675

77-
* In the Parameters section, click **Model Schema**. Double clicking the box moves the parameters to an editable box to try out the function.
76+
* In the Parameters section, click **Model Schema**. Double-clicking the box moves the parameters to an editable box to try out the function.
7877

7978
![](/posts/files/coding-101-rest-basics-ga/assets/images/refguide5.png)
8079

8180
### Things to Try
82-
* Check out the other ticket endpoints in the API Reference Guide. How do they differ from one another?
83-
<br/>
84-
<br/>
81+
* Look at the other ticket endpoints in the API Reference Guide. How do they differ from one another?
8582

8683
### Next Step: Make HTTP calls Using REST

labs/coding-101-rest-basics-ga/4.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
## Step 4. REST in Action: Now let's try it!
1+
## Step 4. REST in Action: Now try it!
22

33
### APIC-EM Example: POST Create a Ticket
44

5-
Let's take a deeper look at the how to use the API to create a service ticket for authentication.
5+
Now, look at how to use the API to create a service ticket for authentication.
66

7-
We need to know how to construct the request to retrieve the service ticket, so we need to use the API docs to determine the:
7+
You need to know how to construct the request to retrieve the service ticket. Use the API docs to determine the:
88

99
* Method
1010
* URL
@@ -20,9 +20,9 @@ https://{APIC-EM-Server}/api/v1
2020
2121
```
2222

23-
Let's look at the description of the ticket API call from the -- <a href="http://devnetapic.cisco.com" target="_blank">APIC-EM API Docs</a>.
23+
Get the description of the ticket API call from the -- <a href="http://devnetapic.cisco.com" target="_blank">APIC-EM API Docs</a>.
2424

25-
`POST /api/v1/ticket`: This method is used to create a new user ticket
25+
`POST /api/v1/ticket`: This method creates a new user ticket
2626

2727

2828
The HTTP call to a create a service ticket is easy.
@@ -32,21 +32,19 @@ https://{APIC-EM-Server}/api/v1/ticket
3232
3333
```
3434

35-
To get the service ticket our request will look like this:
35+
To get the service ticket your request will look like this:
3636

37-
* **Method** - POST
38-
* **URL** - ![https://{APIC-EM-Server}/api/v1/ticket]()
39-
* Substitute {APIC-EM-Server} with the IP address or hostname of the APIC-EM controller you are using.
40-
* If you are not using your own APIC-EM controller, use the Always-On APIC-EM Lab: ![https://devnetapi.cisco.com/sandbox/apic_em]()
37+
* **Method** - `POST`
38+
* **URL** - `https://{APIC-EM-Server}/api/v1/ticket`
39+
* Substitute `{APIC-EM-Server}` with the IP address or hostname of the APIC-EM controller you are using. For example, the Cisco DevNet Learning Labs APIC-EM controller is `https://devnetapi.cisco.com/sandbox/apic_em`.
4140
* **Headers**
42-
* For POST calls, specify the 'Content-Type' as 'application/json' in the header. It's typical to include this header with all REST method (GET, POST, PUT, DELETE …etc) calls.
41+
* Specify the 'Content-Type' as 'application/json'. It's typical to include this header with all HTTP methods (GET, POST, PUT, DELETE) calls.
4342
* **Authentication**
4443
* In this API call, the authentication data is passed in the body.
4544
* **Body**
46-
* The username and password used to log into the APIC-EM Controller must be provided in JSON format in the body.
45+
* Provide the username and password for logging into the APIC-EM Controller in JSON format.
4746

4847
![](/posts/files/coding-101-rest-basics-ga/assets/images/apic-em-request.png)
49-
<br/>
50-
<br/>
48+
5149

5250
### Next Step: Making a REST API Call

0 commit comments

Comments
 (0)