

Building a Self Descriptive HTTP API in ASP.NET Core
source link: https://codeopinion.com/building-self-descriptive-http-api-asp-net-core/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

We have all been doing “web services” forever. My first introduction was in the late 90’s with XML-RPC and WDDX. Followed up soon after with SOAP. Good times. Oh and remember WS-*. Don’t remind me.
Over the last couple years, I’ve really taken an interest in HTTP APIs.
I’ve been meaning to post about my experiences developing an HTTP APIs. It’s been an interesting last couple of years and I think there is quiet a bit to share.
Issues
I can only speak from my experiences and give some of the context about my situations. Hopefully you can relate and translate it to your own projects and make a determination if what I struggled with is beneficial in your context.
There were four major pain points that I ran into developing our HTTP API and Clients.
- Unable to change internal data structures that got exposed/serialized to Clients
- Unable to change endpoint paths/routes
- Endpoint documentation (incoming and outgoing payloads)
- Workflow logic living on the client
HTTP APIs
Sometimes all you need is to do CRUD. Sometimes that’s the last thing you should be doing.
Most examples and getting started tutorials usually demonstrate exposing your database structure and provide GET/POST/PUT/DELETE as away of performing CRUD.
You basically end up with HTTP endpoints that are a 1:1 mapping with a database entities.
This also makes it incredibly hard to change your API.
Go beyond serializing a database row into JSON
I’ve realized that developing an HTTP API is not much different than developing a regular HTML Website.
I started developing my HTTP APIs like I would if I were creating a static HTML or server side rendered HTML web application. This means bringing the concepts we’ve been using for ages with HTTP and HTML such as links and forms.
(Un)Surprisingly, this lead to several benefits. First, our API clients could consume our API with ease. Second, they became dumb. Workflow or business logic stayed on the server and didn’t leak to the client.
Series
This series of posts is going to cover some misconceptions I had in regards to HTTP APIs and REST.
Producing an HTTP API using Hypermedia and various media types.
Consuming an HTTP API that uses Hypermedia.
How you can use CQRS and Hypermedia together.
Similar to my Fat Controller CQRS Diet series, I’m going to convert an existing web application. Currently I’m thinking of using the MVC Music Store again. If anyone has any other suggestions or recommendations about this series, or the sample project to convert, please leave comment or let me know on twitter.
Recommend
-
10
Creating Discoverable HTTP APIs with ASP.NET Core 5 Web API
-
12
0:00 / 1:29:52
-
11
0:00 / 1:15:25 ...
-
10
Your Guide to REST API Versioning in ASP.NET Core Since ASP.NET Core 3.1, you have the ability to version your APIs using a Microsoft NuGet packa...
-
9
Building and consuming GraphQL API in ASP.NET Core 5GraphQL is a platform-independent, language-neutral query language and may be used to run queries and retrieve data. Joydip Kanjilal explains how to use GaphQI in an ASP.NET Co...
-
8
Test run of HTTP Logging in ASP.NET Core 6 Written by Thomas Ardal, December 06, 2021 Ever wanted to log all HTTP requests to your websites? I sure have a...
-
8
如果我们只需要将ASP.NET CORE应用部署到Windows环境下,并且希望获得更好的性能,那么我们选择的服务器类型应该是HTTP.SYS。Windows环境下任何针对HTTP的网络监听器/服务器在性能上都无法与HTTP.SYS比肩。一、HTTP.SYS简介 二、Messa...
-
6
This is a continuation to the previous article on Enforcing HTTPS. While redirecting all non-secure requests to secure URLs is good, a man-in-the-middle can still hi...
-
9
Intro This is part 1 in a series where I will be covering various aspects of building a Web API using the newest version of ASP.NET Core. In this part we will look at building a basic API for a fictive online store. In the fol...
-
7
October 18, 2022 Adding Experimental HTTP Methods To ASP.NET Core ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK