Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (2 votes)
2K views

C# Web API Cheat Sheet

The document provides information about registering for an account and logging in using an API, including making authorized API calls. It describes registering by making a POST call to /api/account/register with a JSON body containing email, password, and confirm password. It describes logging in by making a GET call to /token with an x-www-form-urlencoded body containing grant_type, username, and password to get an authorization token. It describes making authorized calls by including the Authorization header with the token and describes endpoint attributes like Authorize, HttpGet, and Route to control authorization and HTTP verbs.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (2 votes)
2K views

C# Web API Cheat Sheet

The document provides information about registering for an account and logging in using an API, including making authorized API calls. It describes registering by making a POST call to /api/account/register with a JSON body containing email, password, and confirm password. It describes logging in by making a GET call to /token with an x-www-form-urlencoded body containing grant_type, username, and password to get an authorization token. It describes making authorized calls by including the Authorization header with the token and describes endpoint attributes like Authorize, HttpGet, and Route to control authorization and HTTP verbs.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

C#

Sign Up For An Account


To create a new account through the API, you will need to do the following:
Default API Path: /api/account/register
Call Type: POST

WebAPI Body (raw application/json):

Cheatsheet
{
“Email”: “youremail@test.com”,
“Password”: “TestPwd123?”,
“ConfirmPassword”: “TestPwd123?”
}
Get started with WebAPI
including authentication
calls, basic commands, Get Token (Log In)
and more. To log into your account and get the token to be used on all future calls, per-
form the following call:
Default API Path: /token
HTTP Verbs
Call Type: GET
GET Read Body (x-www-form-urlencoded):
POST Create {
PUT Replace grant_type: password
username: youremail@test.com
PATCH Modify password: TestPwd123?
}
DELETE Delete
Making an Authorized Call
IHttpActionResult Once you have your token, to call an API endpoint that requires authorization,
200 Ok make the following additions to whatever call you make:
Headers
302 Redirect
{
400 BadRequest Authorization: “Bearer <token>“
401 Unauthorized }
404 NotFound
Endpoint Attributes
409 Conflict
To modify an endpoint in some way, you can include one or more of the follow-
500 Exception ing attributes:
[Authorize]
Find Me At Everyone who calls this endpoint must include the bearer token. You can
also limit authorization like so: [Authorize (Roles = “Employees”)]
www.IAmTimCorey.com
[HttpGet]
Specifies the type of HTTP verb required to connect to this endpoint.
Other verb can be used as well (HttpPost, HttpPut, etc.)

[Route(“api/Test/MyRoute”)]
Specifies route used to connect to this endpoint. This overrides the
default. Especially useful for deeper paths or method overloading.

You might also like