Skip to content

Commit ed75193

Browse files
author
Jason Jarrett
committed
File -> New -> WebAPI project
1 parent 33591bc commit ed75193

File tree

133 files changed

+36429
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+36429
-0
lines changed

.gitignore

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#OS junk files
2+
[Tt]humbs.db
3+
*.DS_Store
4+
5+
#Visual Studio files
6+
*.[Oo]bj
7+
*.user
8+
*.aps
9+
*.pch
10+
*.vspscc
11+
*.vssscc
12+
*_i.c
13+
*_p.c
14+
*.ncb
15+
*.suo
16+
*.tlb
17+
*.tlh
18+
*.bak
19+
*.[Cc]ache
20+
*.ilk
21+
*.log
22+
*.lib
23+
*.sbr
24+
*.sdf
25+
*.docstates
26+
ipch/
27+
obj/
28+
[Bb]in
29+
[Dd]ebug*/
30+
[Rr]elease*/
31+
*.ide
32+
*.opensdf
33+
34+
#Tooling
35+
_ReSharper*/
36+
*.resharper
37+
[Tt]est[Rr]esult*
38+
*.Tests.VisualState.xml
39+
*.vs10x
40+
41+
#Project and build files
42+
[Bb]uild/Packages/
43+
Temp/
44+
45+
#Subversion files
46+
.svn
47+
48+
# Office Temp Files
49+
~$*
50+
51+
# WCF diagnostic files
52+
*.svclog
53+
54+
# DB Professional files
55+
*.dbmdl
56+
57+
# Include the DebugReleaseImplementations folder which would be ignored by the above
58+
!*DebugReleaseImplementations/
59+
60+
# Files added by the Visual Studio Productivity Power Tools extension
61+
*.docstates
62+
63+
# Files created by the git mergetool
64+
*.orig
65+
66+
# Approval tests
67+
*.received.txt
68+
69+
# NuGet packages
70+
packages/
71+
72+
#
73+
# CUSTOM PROJECT IGNORE
74+
#

SampleWebAPI.sln

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2012
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleWebAPI", "SampleWebAPI\SampleWebAPI.csproj", "{7149B237-522B-4608-A9F8-273C89059851}"
5+
EndProject
6+
Global
7+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8+
Debug|Any CPU = Debug|Any CPU
9+
Release|Any CPU = Release|Any CPU
10+
EndGlobalSection
11+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
12+
{7149B237-522B-4608-A9F8-273C89059851}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13+
{7149B237-522B-4608-A9F8-273C89059851}.Debug|Any CPU.Build.0 = Debug|Any CPU
14+
{7149B237-522B-4608-A9F8-273C89059851}.Release|Any CPU.ActiveCfg = Release|Any CPU
15+
{7149B237-522B-4608-A9F8-273C89059851}.Release|Any CPU.Build.0 = Release|Any CPU
16+
EndGlobalSection
17+
GlobalSection(SolutionProperties) = preSolution
18+
HideSolutionNode = FALSE
19+
EndGlobalSection
20+
EndGlobal
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System.Web;
2+
using System.Web.Optimization;
3+
4+
namespace SampleWebAPI
5+
{
6+
public class BundleConfig
7+
{
8+
// For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725
9+
public static void RegisterBundles(BundleCollection bundles)
10+
{
11+
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
12+
"~/Scripts/jquery-{version}.js"));
13+
14+
bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
15+
"~/Scripts/jquery-ui-{version}.js"));
16+
17+
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
18+
"~/Scripts/jquery.unobtrusive*",
19+
"~/Scripts/jquery.validate*"));
20+
21+
// Use the development version of Modernizr to develop with and learn from. Then, when you're
22+
// ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
23+
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
24+
"~/Scripts/modernizr-*"));
25+
26+
bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/site.css"));
27+
28+
bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
29+
"~/Content/themes/base/jquery.ui.core.css",
30+
"~/Content/themes/base/jquery.ui.resizable.css",
31+
"~/Content/themes/base/jquery.ui.selectable.css",
32+
"~/Content/themes/base/jquery.ui.accordion.css",
33+
"~/Content/themes/base/jquery.ui.autocomplete.css",
34+
"~/Content/themes/base/jquery.ui.button.css",
35+
"~/Content/themes/base/jquery.ui.dialog.css",
36+
"~/Content/themes/base/jquery.ui.slider.css",
37+
"~/Content/themes/base/jquery.ui.tabs.css",
38+
"~/Content/themes/base/jquery.ui.datepicker.css",
39+
"~/Content/themes/base/jquery.ui.progressbar.css",
40+
"~/Content/themes/base/jquery.ui.theme.css"));
41+
}
42+
}
43+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Web;
2+
using System.Web.Mvc;
3+
4+
namespace SampleWebAPI
5+
{
6+
public class FilterConfig
7+
{
8+
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
9+
{
10+
filters.Add(new HandleErrorAttribute());
11+
}
12+
}
13+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web;
5+
using System.Web.Mvc;
6+
using System.Web.Routing;
7+
8+
namespace SampleWebAPI
9+
{
10+
public class RouteConfig
11+
{
12+
public static void RegisterRoutes(RouteCollection routes)
13+
{
14+
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
15+
16+
routes.MapRoute(
17+
name: "Default",
18+
url: "{controller}/{action}/{id}",
19+
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
20+
);
21+
}
22+
}
23+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web.Http;
5+
6+
namespace SampleWebAPI
7+
{
8+
public static class WebApiConfig
9+
{
10+
public static void Register(HttpConfiguration config)
11+
{
12+
config.Routes.MapHttpRoute(
13+
name: "DefaultApi",
14+
routeTemplate: "api/{controller}/{id}",
15+
defaults: new { id = RouteParameter.Optional }
16+
);
17+
18+
// Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type.
19+
// To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries.
20+
// For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712.
21+
//config.EnableQuerySupport();
22+
23+
// To disable tracing in your application, please comment out or remove the following line of code
24+
// For more information, refer to: http://www.asp.net/web-api
25+
config.EnableSystemDiagnosticsTracing();
26+
}
27+
}
28+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Text;
3+
using System.Web;
4+
using System.Web.Http.Description;
5+
6+
namespace SampleWebAPI.Areas.HelpPage
7+
{
8+
public static class ApiDescriptionExtensions
9+
{
10+
/// <summary>
11+
/// Generates an URI-friendly ID for the <see cref="ApiDescription"/>. E.g. "Get-Values-id_name" instead of "GetValues/{id}?name={name}"
12+
/// </summary>
13+
/// <param name="description">The <see cref="ApiDescription"/>.</param>
14+
/// <returns>The ID as a string.</returns>
15+
public static string GetFriendlyId(this ApiDescription description)
16+
{
17+
string path = description.RelativePath;
18+
string[] urlParts = path.Split('?');
19+
string localPath = urlParts[0];
20+
string queryKeyString = null;
21+
if (urlParts.Length > 1)
22+
{
23+
string query = urlParts[1];
24+
string[] queryKeys = HttpUtility.ParseQueryString(query).AllKeys;
25+
queryKeyString = String.Join("_", queryKeys);
26+
}
27+
28+
StringBuilder friendlyPath = new StringBuilder();
29+
friendlyPath.AppendFormat("{0}-{1}",
30+
description.HttpMethod.Method,
31+
localPath.Replace("/", "-").Replace("{", String.Empty).Replace("}", String.Empty));
32+
if (queryKeyString != null)
33+
{
34+
friendlyPath.AppendFormat("_{0}", queryKeyString);
35+
}
36+
return friendlyPath.ToString();
37+
}
38+
}
39+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Net.Http.Headers;
4+
using System.Web;
5+
using System.Web.Http;
6+
7+
namespace SampleWebAPI.Areas.HelpPage
8+
{
9+
/// <summary>
10+
/// Use this class to customize the Help Page.
11+
/// For example you can set a custom <see cref="System.Web.Http.Description.IDocumentationProvider"/> to supply the documentation
12+
/// or you can provide the samples for the requests/responses.
13+
/// </summary>
14+
public static class HelpPageConfig
15+
{
16+
public static void Register(HttpConfiguration config)
17+
{
18+
//// Uncomment the following to use the documentation from XML documentation file.
19+
//config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml")));
20+
21+
//// Uncomment the following to use "sample string" as the sample for all actions that have string as the body parameter or return type.
22+
//// Also, the string arrays will be used for IEnumerable<string>. The sample objects will be serialized into different media type
23+
//// formats by the available formatters.
24+
//config.SetSampleObjects(new Dictionary<Type, object>
25+
//{
26+
// {typeof(string), "sample string"},
27+
// {typeof(IEnumerable<string>), new string[]{"sample 1", "sample 2"}}
28+
//});
29+
30+
//// Uncomment the following to use "[0]=foo&[1]=bar" directly as the sample for all actions that support form URL encoded format
31+
//// and have IEnumerable<string> as the body parameter or return type.
32+
//config.SetSampleForType("[0]=foo&[1]=bar", new MediaTypeHeaderValue("application/x-www-form-urlencoded"), typeof(IEnumerable<string>));
33+
34+
//// Uncomment the following to use "1234" directly as the request sample for media type "text/plain" on the controller named "Values"
35+
//// and action named "Put".
36+
//config.SetSampleRequest("1234", new MediaTypeHeaderValue("text/plain"), "Values", "Put");
37+
38+
//// Uncomment the following to use the image on "../images/aspNetHome.png" directly as the response sample for media type "image/png"
39+
//// on the controller named "Values" and action named "Get" with parameter "id".
40+
//config.SetSampleResponse(new ImageSample("../images/aspNetHome.png"), new MediaTypeHeaderValue("image/png"), "Values", "Get", "id");
41+
42+
//// Uncomment the following to correct the sample request when the action expects an HttpRequestMessage with ObjectContent<string>.
43+
//// The sample will be generated as if the controller named "Values" and action named "Get" were having string as the body parameter.
44+
//config.SetActualRequestType(typeof(string), "Values", "Get");
45+
46+
//// Uncomment the following to correct the sample response when the action returns an HttpResponseMessage with ObjectContent<string>.
47+
//// The sample will be generated as if the controller named "Values" and action named "Post" were returning a string.
48+
//config.SetActualResponseType(typeof(string), "Values", "Post");
49+
}
50+
}
51+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Web.Http;
3+
using System.Web.Mvc;
4+
using SampleWebAPI.Areas.HelpPage.Models;
5+
6+
namespace SampleWebAPI.Areas.HelpPage.Controllers
7+
{
8+
/// <summary>
9+
/// The controller that will handle requests for the help page.
10+
/// </summary>
11+
public class HelpController : Controller
12+
{
13+
public HelpController()
14+
: this(GlobalConfiguration.Configuration)
15+
{
16+
}
17+
18+
public HelpController(HttpConfiguration config)
19+
{
20+
Configuration = config;
21+
}
22+
23+
public HttpConfiguration Configuration { get; private set; }
24+
25+
public ActionResult Index()
26+
{
27+
return View(Configuration.Services.GetApiExplorer().ApiDescriptions);
28+
}
29+
30+
public ActionResult Api(string apiId)
31+
{
32+
if (!String.IsNullOrEmpty(apiId))
33+
{
34+
HelpPageApiModel apiModel = Configuration.GetHelpPageApiModel(apiId);
35+
if (apiModel != null)
36+
{
37+
return View(apiModel);
38+
}
39+
}
40+
41+
return View("Error");
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)