At the end of this class, you will be able to:
wilson-espina/jsd-9-resources
repo to your computerDocuments/JSD/jsd-9-resources/10-ajax-apis
A Web Service is a resource that’s made available over the internet.
Web Services may be written in a variety of languages. They expose data via their APIs and communicate via the same protocols used for the World Wide Web.
An API is the code that governs the access point(s) for the server.
Type of Exercise
Location
Timing
10 mins |
|
HTTP VERB | OPERATION |
---|---|
GET | Retrieve a new resource |
POST | Create a new resource |
PUT | Replace a resource |
PATCH | Update an existing resource |
DELETE | Delete a resource resource |
HTTP VERB | OPERATION |
---|---|
GET | Retrieve a new resource |
POST | Create a new resource |
PUT | Replace a resource |
PATCH | Update an existing resource |
DELETE | Delete a resource resource |
GET
and POST
are most widely used.CATEGORY | RESPONSE CLASS | COMMON EXAMPLES |
---|---|---|
2xx | Success |
|
3xx | Redirection |
|
4xx | Client Error |
|
5xx | Server Error |
|
When requesting information about a resource from an application, RESTful design patterns dictate that you should be able to do 7 key actions.
We call these the 7 restful routes and they are created by combining:
Consider the following 7 RESTFUL routes for requesting a resource of photos.
URL | HTTP VERB | Action | Result |
---|---|---|---|
| GET | Index | Display all photos |
| GET | New | Show a form to upload a new photo |
| POST | Create | Add a new photo to database, then redirect |
| GET | Show | Show info about one photo |
| GET | Edit | Show edit for for one photo |
| PUT | Update | Update a particular photo, then redirect |
| DELETE | Destroy | Destroy a particular photo, then redirect |
fetch(url)
.then((response) => {
if (!response.ok) throw Error(response.statusText);
return response.json();
})
.then((responseData) => {
const data = JSON.stringify(responseData);
// do something with the data
});
Open up: 01-fetch-ajax-codealong
METHOD | DESCRIPTION |
---|---|
| Retrieve a new resource |
| Create a new resource |
Open up: 01-fetch-ajax-codealong
Objective
Location
02-fetch-ajax-exercise
Timing
10 mins |
|
(Lesson #10)