CS296N Web Development 2: ASP.NET

Creating a REST Web API

 

Weekly topics 
1. Intro to course and Input validation6. Security
2. Identity7. Creating a Web Service
3. Authentication8. Consuming a Web Service
4. Authorization9. Docker containers
5. Async/Await & Complex Domain Model10. Term project

Contents

Creating a REST Web API ContentsAnnouncementsWeb APIsREST ArchitectureHTTP MessagesHTTP requestsREST Resource RepresentationConsuming a REST ServiceWeb Service ClientsWeb Service TestingReferences

Announcements

 

Web APIs

An ASP.NET Core Web API (aka web service) can be used in several ways:

  1. 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.

  2. As a way to create a web service

    • Think of a web service as a web site that doesn't have a UI, it is meant to be accessed by a computer not a human.

There are two main scenarios in which web services are used:

  1. To facilitate a Service Oriented Architecture in which different components of a system communicate over a network.
  2. To provide a service that can be used by third parties or subscribers.

REST Architecture

REST is not really a new protocolit is just another way to use HTTP.

Examples from OpenWeather:

HTTP Messages

HTTP requests

Requests have these parts:

  1. Start linethis includes the URL and things that are appended to it.

    • An HTTP Method (a verb) Common methods are: GET, POST, PUT, PATCH, DELETE.

    • Request targetnormally a URL.

    • HTTP version.

    • Example:

  2. Headerthis 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:

  3. BodyNot all requests have a body, but request methods that send data to be stored (POST, PUT, etc.) will have a body.

    • Example:

REST Resource Representation


 

Consuming a REST Service

Web Service Clients

Web Service Testing


References


Creative Commons License ASP.NETCore MVC Lecture Notes by Brian Bird are licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.