REST Services

Representational State Transfer
Rest is an architectural style
It's not a standard itself, but does use standards such as HTTP, URL, XML, etc.


This is an open source library designed to make consuming APIs from .NET easier.
RestSharp makes it easy by abstracting away some of the complication of dealing with raw HTTP requests and providing a developer-friendly way of getting at what's important: the data.

Crafting an HTTP request can be done in several ways, with the most common way being the use of System.Net.Http.HttpClient or the simpler System.Net.WebClient.
System.Net.HttpWebRequest is not recommended unless you're doing something specific that requires lower-level access.

HttpClient is the newest one, requiring the Microsoft .NET Framework 4.5 and exposing only asynchronous methods for sending requests.
It's the most similar to RestSharp in that it's easy to use (not overly abstract and not overly complicated either), but because it requires the .NET Framework 4.5, not every application can take advantage of it.

WebClient is very simple and a great choice for just making GET requests, but once you need to start using verbs like PUT or DELETE the code starts to get quite a bit messier.

namespace RestSharp 

Calling REST

Download .NET 6.0 Runtime
Open VS Code
Check the dotnet version

dotnet --info 

Install the C# Extension

Create folder

cd c:\temp\vscode\consoleapp1 
dotnet new console
code -a.

dotnet run 

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext