Запросы к REST API на C#

Введение

Нужно установить RestSharp

dotnet add package RestSharp

GET

var client = new RestClient("https://example.com/engine/api/v1/wfs?limit=50&offset=0"); var request = new RestRequest(Method.GET); request.AddHeader("accept", "application/json"); request.AddHeader("Authorization", "Bearer a-proper-token-goes-here"); IRestResponse response = client.Execute(request);

POST

var client = new RestClient("https://example.com/engine/api/v1/wfs"); var request = new RestRequest(Method.POST); request.AddHeader("accept", "application/json"); request.AddHeader("Authorization", "Bearer a-proper-token-goes-here"); request.AddHeader("content-type", "application/json"); request.AddParameter("application/json", "{\"status\":\"WAITING\",\"approver_can_revoke\":false,\"target_role_revoked\":false,\"can_bypass_revoke_wf\":false}", ParameterType.RequestBody); IRestResponse response = client.Execute(request);

PUT

var client = new RestClient("https://example.com/engine/api/v1/wfs/wf_id"); var request = new RestRequest(Method.PUT); request.AddHeader("accept", "application/json"); request.AddHeader("Authorization", "Bearer a-proper-token-goes-here"); request.AddHeader("content-type", "application/json"); IRestResponse response = client.Execute(request);

Banner image

DELETE

var client = new RestClient("https://example.com/engine/api/v1/wfs/wf_id"); var request = new RestRequest(Method.DELETE); request.AddHeader("accept", "application/json"); request.AddHeader("Authorization", "Bearer a-proper-token-goes-here"); IRestResponse response = client.Execute(request);

Article author: Andrei Olegovich

Похожие статьи
.NET
Как узнать тип переменной C#
REST

Search this site

Subscribe to Telegram channel @aofeed to follow new articles and updates to old ones

Go to channel

@aofeed

Ask a question in the Telegram group

@aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su, info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: