0% found this document useful (0 votes)
9 views

2024 - Inf 354 Api

This document discusses creating and deploying APIs using .NET Core and C#. It covers REST principles, HTTP verbs, routing, and creating a practical API. Key points include stateless communication in REST, standard HTTP verbs like GET and POST, and attribute routing in .NET Core Web APIs.

Uploaded by

maahlewest
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

2024 - Inf 354 Api

This document discusses creating and deploying APIs using .NET Core and C#. It covers REST principles, HTTP verbs, routing, and creating a practical API. Key points include stateless communication in REST, standard HTTP verbs like GET and POST, and attribute routing in .NET Core Web APIs.

Uploaded by

maahlewest
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

INF 354:

Advanced
Programming
API 1
Learning Outcome:

❖ Understand, develop, and deploy Application


Programming Interfaces (APIs) using .NET Core
cross-platform framework and the C# programming
language to connect to repositories and data
sources such as databases.

Learning Objectives:

❖ To understand the purpose of creating an


API
❖ Develop a WebAPI
Outline

❖ Introduction
❖ REST
❖ HTTP Verbs
❖ Routing
❖ Database
❖ Practical
API 1

Introduction
API

• An API (Application Programming Interface) connects two or more


applications. It allows two applications to communicate with one
another.

API GUI

Client User
Server

• An API making use of HTTP is called a Web API.


Different types of Web APIs

Remote Procedure Call, RPC.


• Clients can call functions on the server.
Remote Method Invocation, RMI.
• Clients can call methods on objects on the server.
Representational State Transfer, REST.
• Clients can apply CRUD operations on resources on the server.
Representational State Transfer (REST)

• A style of software architecture for distributed hypermedia systems


such as the World Wide Web.
• Introduced in the doctoral dissertation of Roy Fielding
• One of the principal authors of the HTTP specification.
• Rest is a set of principles that define how web services should be
designed and interact with each other.
• A collection of network architecture principles that outline how
resources are defined and addressed
Representational State Transfer (REST)

• Rest, emphasizes a stateless client-server architecture.


• This principle means that the server does not store any state about
the client session on the server side.
• Instead, each request from the client to the server must contain all
the information necessary to understand and complete the request.
• Adhering to a stateless communication model, RESTful services
aim to enhance performance, reliability, and scalability while
ensuring a uniform and standardized web services architecture.
Representational State Transfer (REST)

• Implication of having REST as a stateless client-server


• Self-contained Requests
• Session State
• Scalability
• Caching
• Simplicity and Uniform Interface
REST - not a Standard

REST is not a standard


• JSR 311: JAX-RS: The JavaTM API for RESTful Web Services

But it uses several standards:


• HTTP
• URL
• XML/HTML/GIF/JPEG/etc (Resource Representations)
• text/xml, text/html, image/gif, image/jpeg, etc (Resource Types, MIME Types)
ASP.NET Core

ASP.NET Core provides a powerful and flexible platform for building restful
APIs with its support for

• HTTP verbs
• Routing
• Model binding,
• Response types.
HTTP Verbs

• GET – (Read) Get information. GET requests must be safe and


idempotent, which means that no matter how many times they are
repeated with the same parameters, the results must be the same.
• POST – (Create) Instruct the resource at the URI to perform an
action on the provided entity.
• PUT – (Update) Add an entity to a URI. PUT can be used to
create a new entity or to update an existing one.
• PATCH - Update only the specified fields of a URI entity.
• DELETE - Request the removal of a resource; however, the
resource does not have to be removed right away..
HTTP Verbs
Get: https://myapi.com/api/employees (Get all Employees)

Get: https://myapi.com/api/employees/{id} (Get single Employees by id)

POST: https://myapi.com/api/employees (Create an Employee)

PUT: https://myapi.com/api/employees /{id} (Update an Employees by id)

Delete: https://myapi.com/api/employees /{id} (Delete an Employee by id)


Web API Routing

• It routes incoming HTTP requests to a specific action method on a Web API


controller.

• Attribute routing uses [Route()] attribute to define routes. The Route attribute
can be applied on any controller or action method.
public class StudentController : ApiController
{
[Route("api/student/names")]
public IEnumerable<string> Get()
{
return new string[] { "student1", "student2" };
}
}
Practical – (Creating a new WebAPI)
Practical – (Creating a new WebAPI)
Practical – (Creating a new WebAPI)
ZAHikes
Hikes
Name Type
Province
ID Unique Identifier (GUID)
Name Type
Name String
ID Unique Identifier (GUID)
Description String
Code String
LengthInKm Double
Name String
HikeImageUrl String
RegionImageUrl String
ProvinceId Unique Identifier (GUID)

DifficultyId Unique Identifier (GUID)

Difficulty
Name Type

ID Unique Identifier (GUID)

Name String
The End

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy