CS296N Web Development 2: ASP.NET
Weekly topics | |
---|---|
1. Intro to course and Input validation | 6. Security |
2. Identity | 7. Creating a Web Service |
3. Authentication | 8. Consuming a Web Service |
4. Authorization | 9. Docker containers |
5. Async/Await & Complex Domain Model | 10. Term project |
Creating a REST Web API ContentsAnnouncementsWeb APIsREST ArchitectureHTTP MessagesHTTP requestsREST Resource RepresentationConsuming a REST ServiceWeb Service ClientsWeb Service TestingReferences
An ASP.NET Core Web API (aka web service) can be used in several ways:
As a way to add AJAX to Razor views to make them more efficient. The reservation web app in Ch. 20 of Freeman (2017) is an example of this.
As a way to create a web service
There are two main scenarios in which web services are used:
Advantages of using web services:
Allows computing services to be distributed across:
Provides a service that is:
Types of Web Services
SOAP - Simple Object Access Protocol
REST - Representational State Transfer
REST is not really a new protocol—it is just another way to use HTTP.
Examples from OpenWeather:
Requests have these parts:
Start line—this includes the URL and things that are appended to it.
An HTTP Method (a verb) Common methods are: GET, POST, PUT, PATCH, DELETE.
Request target—normally a URL.
HTTP version.
Example:
xxxxxxxxxx
POST /api/Book HTTP/1.1
Host: localhost:5000
Header—this is optional and provides information about the request; such as the source of the request, the format of the body, etc. The information included depends on the type and content of the request. For requests that have a body, you can specify its format here.
Example:
xxxxxxxxxx
Content-Type:application/json
Body—Not all requests have a body, but request methods that send data to be stored (POST, PUT, etc.) will have a body.
Example:
xxxxxxxxxx
{
"title": "Huckleberry Finn",
"date": "4/3/1875",
"name": "Mark Twain",
"birthday": "11/30/1835"
}
Resources - a REST service provides access to resources, which can be any kind of digital object: image, video, text, etc.
There is no restriction on the way resources can be represented, but the two most common means are:
Can be written in any programming language
Can run on any OS
Normally integrated into other software (many apps include code that calls a web service)
Can run on any type of platform - server, browser, mobile app, etc.
Server-side client code can be written in any language that runs on the server, but
ASP.NETCore MVC Lecture Notes by Brian Bird are licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.