A stripped-down version of Visual Studio's out-of-the-box Web API 2.x project template to provide bare-bones support for, in particular, ASP.NET Identity web services (e.g., /API/Account/Register/
). Does not include any of the MVC, Web API Help, or other web-based devependencies that ship with the out-of-the-box template. Additionally includes an OData controller for exposing other elements from the Model
project, including User
, Post
, and Comment
end points.
Note: The followings provides a high-level overview of the out-of-the-box capabilities of OData as they apply to the
WebApi
project. For more in-depth coverage of OData, visit odata.org.
The following endpoints are exposed by the OData implementation:
/OData/Users
/OData/Posts
/OData/Comments
Each OData endpoint supports standard OData parameters via the Query String, including:
?$filter=
(e.g.,contains(Comments/Body, '@Jeremy')
)?$orderby=
(e.g.,DateCreated desc
)?$top=
and$skip=
for paging?$expand=
(e.g.,Comments/Likes
)?$select=
(e.g.,Title,Body,DateCreated
)
Individual records can be retrieved from an OData collection using the ('PrimaryKey')
format. For instance:
/Odata/Users('d0457c7c-798c-4a60-b4bd-030bcad7062b')
/Odata/Posts(5)
/OData/Comments(10)
Note: The Web API OData implementation does not support selecting individual records from entity relationships. For instance,
/Odata/Posts(5)/Comments
is allowed, but/Odata/Posts(5)/Comments(1)
will return an error. Instead, this would need to be retrieved using/Odata/Comments(1)
.
Note: The following is simply intended to provide a quick overview of the out-of-the-box endpoints associated with the Web API 2.x project. There are many available resources that provide more thorough investigation of these endpoints elsewhere on the internet.
The following endpoints are defined by the out-of-the-box Web API 2.x project template:
/API/Account/UserInfo
*/API/Account/Logout
[POST]/API/Account/ManageInfo?returnUrl={returnUrl}&generateState={generateState}
/API/Account/ChangePassword
[POST]/API/Account/SetPassword
[POST]/API/Account/AddExternalLogin
[POST]/API/Account/RemoveLogin
[POST]/API/Account/ExternalLogin?provider={provider}&error={error}
/API/Account/ExternalLogins?returnUrl={returnUrl}&generateState={generateState}
/API/Account/Register
[POST]/API/Account/RegisterExternal
* [POST]
* Requires Authentication: The
UserInfo
andRegisterExternal
endpoints require bearer authentication. The bearer token can be retrieved either from the/Token
endpoint, or from the/API/Account/ExternalLogin
endpoint (as returned via the#access_token
). In turn, the bearer token should be prefixed withbearer
and relayed via theAuthorization
HTTP header.
The following provide examples of the data expected by each POST
endpoint.
{
"OldPassword": "OldPassword",
"NewPassword": "NewPassword",
"ConfirmPassword": "NewPassword"
}
{
"NewPassword": "NewPassword",
"ConfirmPassword": "NewPassword"
}
{
"ExternalAccessToken": "sample string 1"
}
{
"LoginProvider": "Facebook",
"ProviderKey": "10152759761386507"
}
{
"Email": "[email protected]",
"Password": "Password",
"ConfirmPassword": "Password"
}
{
"Email": "[email protected]"
}
While the Web API seeks to maintain parity with the out-of-the-box Web API project template, a number of changes have been made to the templates. These include:
- All files have been reformated and commented, including the use of XmlDocs.
- Files have been broken down to one file per class; notably, this affects the
/Models
directory. - Entity Framework dependencies have been moved to the
Model
project for integration with the data model. - Web API OData controllers have been added for
Comments
andPosts
based on theModel
project. - Added
username
to the hash generated by the/API/Account/RegisterExternal
end point via theApplicationOAuthProvider.cs
class as a convenience.
Important: In the
Startup.Auth.cs
file, this template overrides theFacebookAuthenticationProvider
class'sOnAuthenticated
property in order to set theDefaultNameClaimType
toUsername
, and also adds theFacebookAuthenticationOptions.Scope
collection. This allows the Web API's external token for Facebook to be used with the Web API's//API/Account/RegisterExternal
endpoint (which expects an email address for the username), and//API/Account/UserInfo
(which expects that the token's username claim will match that same email address).
The out-of-the-box Web API template includes a number of dependencies in order to support Web API Help pages. While Web API Help pages are useful, they a) necessitate a much larger footprint for the project, and b) are only compatible with the basic Web API controller (not the Web API OData controller). For these reasons, the following have been removed from the out-of-the-box template:
/App_Start
/BundleConfig.cs
/FilterConfig.cs
/RouteConfig.cs
/Areas
/HelpPages
/Content
/Controllers
/ValuesController.cs
/Fonts
/Scripts
/Views
/favicon.ico
/Project_Readme.html