
Learn to design, code, document, and test robust restful APIs in C# with ASP.NET Core, using postman and FTP client to consume third party services, with validation and error handling.
Design and build a restful API with ASP.NET Core, test with Postman, document with Swagger, and create an API client using HttpClient.
Review prerequisites and tools, explain rest concepts, plan a restful API, explore various TDP methods, and cover HTTP status codes to shape the API design.
Identify prerequisites such as experience with dot net core or dot net mvc web api and c-sharp, and note the use of visual studio 2022, postman, and a web browser.
Rest stands for representational state transfer, an architectural constraint by Roy Fielding; protocol agnostic and typically implemented with HTTP, where methods, headers, and parameters play a key role.
Explore http methods such as get, post, put (idempotent), and delete, and learn common status codes like 200 ok, 201 created, 204 no content, and 4xx–5xx errors.
Plan a restful api by designing url structure, mapping http methods, defining headers, payloads, and status codes; enable paging with skip and take, supporting get, post, put, delete on courses.
Explore what REST is and isn't, learn essential HTTP methods and status codes, and plan a RESTful API for courses and students as you begin development.
Set up the models project by creating a .NET class library in Visual Studio 2022 for course entities, including course, professor, and student with IDs and initialized students list.
Create a memory-backed services project in the robust REST APIs course, implementing ICourseService and a core service to manage courses and students, with paging and image upload support.
Create an ASP.NET Core Web API project to host a RESTful API, target .NET 6.0, enable HTTPS, reference models and services, and focus on the startup program.
Implement a courses api controller with a get list endpoint at api/courses that returns a sliced in-memory course list, serialized to json, while avoiding social security numbers and student data.
Create data transfer objects to hide sensitive data when sending API responses. Map essential fields from course and professor into the DTO and update the controller to return DTOs.
Learn to implement dependency injection in ASP.NET Core by injecting ICourseService into the courses controller, registering the service in program.cs, and verifying with Postman.
Learn to configure AutoMapper with a profile, map between course and course dto (including professor name), and inject the mapper via dependency injection.
Learn to implement search and pagination in robust rest APIs with c#, asp.net core, and httpclient by adding skip, take, and search query parameters and a shared request class.
Add a get by id endpoint returning a single course dto, return 404 not found when missing, and 200 ok with the course data, while suppressing detailed errors in production.
Add a course via http post by mapping the request to a course entity with AutoMapper, return the course DTO, and include a 201 created with a location header.
Enforce data validity for ad course requests with data annotations, custom validation attributes, and fluent validation, ensure name is not empty and max 100 characters, and return 422 on errors.
Master content negotiation by handling JSON and XML via Content-Type and Accept headers. Ensure 406 responses and support XML payloads with 201 created results.
Implement a put endpoint to update courses using an update course request, map to a course, and return 204 or 404 when the course ID is missing.
Implement a delete course endpoint in the courses api using an http delete method, validating the course exists, returning not found if missing, otherwise deleting and returning no content.
Configure swagger to document endpoints, parameters, and media types with defaults. Include XML comments and produces attributes to expose common responses.
Design and test a robust rest api for managing courses, using proper http status codes, input validation, and output filtering, with json and xml support and swagger documentation.
Plan versioning for multi-version APIs and prepare a version two, focusing on students in courses, student ID images, basic authentication, and documentation for multiple versions.
Plan version 2 of the API to support course-based student management, including listing, retrieving, adding, updating, and deleting students, and uploading or deleting a student id image.
Prepare version 2 of the api by duplicating v1 into a v2 namespace, preserving v1 for existing users, and updating Swagger to expose both endpoints for courses and students.
Create a student controller that lists students in a course and retrieves a single student. Validate course and student existence, map to student DTOs, and return 200 ok or 404.
Introduce the Set ID image API that validates course and student, accepts a form data file via IFormFile, converts it to bytes, and returns no content on success.
Implement the delete student ID image method, validate course and student IDs, pass null for image and file name, and verify no content responses (204) for correct IDs.
implement a basic authentication scheme for api v2 using a custom authentication handler, parse base64-encoded credentials from the authorization header, and enforce authentication on endpoints via a policy attribute.
Add a basic authentication security definition and security requirement to swagger, then verify via the authorized button that credentials unlock access to courses API, transitioning from 401 to success.
Develop a version two API by adding student endpoints, enabling file uploads, and implementing basic authentication, then prepare to build an API client to consume the API.
Write and test an API client using the http client class, implement robust exception handling, and build unit tests with mstest and fluent assertions through test-driven development.
Learn test driven development by writing unit tests first, cover good, bad, and edge cases, implement code, run tests, and iterate until all tests pass.
Prepare for the api client and tests by adding a class library named Circle Dot integrations and an MSI test project named integration score tests, then add fluent assertions.
Define a public v2 API client interface for courses and students with asynchronous methods and cancellation tokens, then scaffold course models and build a stub client driven by unit tests.
Define api exception classes for the client, including a generic api exception, a 422 validation exception with errors, a 404 not found, and a 401 authorization exception, enabling unit tests.
Create a unit test class for the courses and students API client, using a test initialize method and fluent assertions to validate async get courses with skip, take, and search.
Implement the get courses method in the API client, including basic authentication, building the request URL with search, skip, and take parameters, and validating responses through unit tests.
Implement exception handling for a rest api client by validating 200 ok responses, handling 401 unauthorized with authorization exceptions, and wrapping calls in a try catch to raise api exceptions.
Create a single method to build the http client with base address and authorization, and test get course for id 1, 1000 not found, and bad credentials.
Explore add course tests for robust rest APIs in C#, ASP.NET Core, HttpClient, including valid and invalid inputs, JSON serialization, handling validation and authorization exceptions, and API v2 routing.
Learn validation error handling for robust rest APIs by deserialising a 422 response, collecting per-property errors, and throwing a validation exception in the api client.
Update course using the API client with a put request, serialize the update to JSON, and handle authorization and not found errors while validating with unit tests.
Develop and test the delete course API by creating a course, deleting it, and confirming not found or unauthorized responses; implement delete with http client returning no content on success.
Develop and test a put operation uploading a student id image via multipart form data using a byte array from an embedded image, with api client calls and exception handling.
Implement delete student identification image methods and tests using a TDP client; delete via course and student IDs, map unauthorized and not found to exceptions, return no content on success.
Build an api client using http client with test driven development and unit tests. Call api endpoints using various http methods and handle status codes with robust exception handling.
Master planning, building, testing with Postman, and documenting robust REST APIs and clients using ASP.NET Core and HttpClient, including validation, versioning, security with basic authentication, and Swagger documentation.
Hello fellow .NET Developers! Welcome to this course about creating and consuming RESTful APIs.
RESTful APIs are an important way in which applications expose functionality to the other applications. Being able to build your own professional API for other companies to consume, or to build your own professional API client to consume other companies' APIs is an important and marketable skill.
In the first part of this course, we will learn what a RESTful API is and design one to manage Course and Student data.
In the next part of this course, we will build and thoroughly test this RESTful API. We will go beyond the basics to ensure that the API is of high quality so that other developers can reliably call it. We do this by ensuring proper error handling, boundary condition handling, thorough testing, and documentation generation. Along the way we will use ASP.NET Core to create the RESTful API, Swagger to view the fully documented API, and Postman to test it.
In the final part of this course, we will write a professional and robust API client to consume our RESTful Courses API. As before, we will go beyond the basics to ensure it can be easily and reliably be incorporated into any .NET application. We do this by ensuring proper error handling, boundary condition handling, and thorough testing. Along the way we will use HttpClient to build our API Client using solid object-oriented programming principles and we will Unit test it using Test-Driven Development with MSTest.
Happy learning!