Your question is not clear.
Typically with 4.8 you would create a webapi project that is hosted by IIS. IIS supplies the main request pipline, and your project just supplies callbacks. The closest to your sample is a http module
https://learn.microsoft.com/en-us/previous-versions/aspnet/ms227673(v=vs.100)
If you meant a self hosting web server not hosted by IIS, then you use the self hosting module
https://learn.microsoft.com/en-us/aspnet/web-api/overview/older-versions/self-host-a-web-api
Or you can use owin