Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
2f102a4
Remove old solution
sakapon Mar 29, 2018
15d819a
Create project
sakapon Mar 29, 2018
e12871a
Install Microsoft.AspNet.WebApi.HelpPage 5.2.3
sakapon Mar 29, 2018
29c62a0
Register areas
sakapon Mar 29, 2018
237fdf3
Create test project
sakapon Mar 29, 2018
3cf8eb9
Install Blaze
sakapon Mar 29, 2018
d9317e0
Update project settings
sakapon Mar 29, 2018
d6c95e0
Update help page
sakapon Mar 29, 2018
ca3fd0a
Add controller
sakapon Mar 30, 2018
aa176ca
Add actions
sakapon Mar 31, 2018
51c60d1
Add comments
sakapon Mar 31, 2018
43b7a99
Return strict type
sakapon Mar 31, 2018
4d2bc10
Update routing for order on help page
sakapon Mar 31, 2018
8804c71
Add comments
sakapon Mar 31, 2018
3409b6f
Update comments
sakapon Mar 31, 2018
23d1011
Remove XML formatter
sakapon Mar 31, 2018
d2f3499
Enable CORS
sakapon Mar 31, 2018
46db887
Fix CRLF
sakapon Mar 31, 2018
117b51a
Add helper class
sakapon Mar 31, 2018
70f30f5
Show link to API with sample Int32 parameters
sakapon Mar 31, 2018
5be8f84
Install KTools.VersionIncrement
sakapon Apr 1, 2018
b20ff06
Version up
sakapon Apr 1, 2018
897c06a
Update layout
sakapon Apr 1, 2018
7b40408
Update layout
sakapon Apr 2, 2018
50c69dd
Update layout
sakapon Apr 2, 2018
6bedaa8
Update layout
sakapon Apr 2, 2018
9bc60ff
Require HTTPS connection
sakapon Apr 2, 2018
223cf5f
Version up
sakapon Apr 2, 2018
85ca0db
Install Microsoft.AspNet.WebApi.Client 5.2.3
sakapon Apr 2, 2018
0c90210
Add helper class
sakapon Apr 2, 2018
014c171
Add test for architecture
sakapon Apr 2, 2018
0ea1752
Install Blaze
sakapon Apr 2, 2018
337a98c
Add test
sakapon Apr 2, 2018
5a95eab
Add helper method
sakapon Apr 3, 2018
0eaf950
Add test
sakapon Apr 3, 2018
088da2a
Add test
sakapon Apr 3, 2018
774a96a
Add test
sakapon Apr 3, 2018
e7d34d7
Update test
sakapon Apr 3, 2018
1e1b9f7
Add test page
sakapon Apr 3, 2018
6cc9584
Copy old version of CSHTML
sakapon Apr 3, 2018
a06ad8a
Update test page
sakapon Apr 3, 2018
bb8147c
Show assembly file version
sakapon Apr 3, 2018
faa5b5f
Update comments
sakapon Apr 3, 2018
5694ad7
Enable HTML tags in XML document #2
sakapon Apr 3, 2018
821208b
Create Hosting.md
sakapon Apr 5, 2018
03f61cf
Update Hosting.md
sakapon Apr 5, 2018
8807afb
Create Deployment.md
sakapon Apr 5, 2018
2251437
Update Hosting.md
sakapon Apr 5, 2018
8aa2601
Add SampleUri property
sakapon Apr 6, 2018
669df78
Set sample objects for type
sakapon Apr 6, 2018
8d62a82
Get sample object by dynamic execution #3
sakapon Apr 6, 2018
07f5964
Version up
sakapon Apr 6, 2018
cc038d4
Install EntityFramework
sakapon Apr 7, 2018
e2f789d
Add DbContext for test
sakapon Apr 7, 2018
a38db15
Add test for SQL Server
sakapon Apr 7, 2018
c3fd455
Update test
sakapon Apr 7, 2018
9f06538
Use property for title
sakapon Apr 7, 2018
3baa867
Set page title
sakapon Apr 7, 2018
8450570
Refactor
sakapon Apr 7, 2018
86dffd2
Version up
sakapon Apr 7, 2018
d3aaeef
Add test
sakapon Apr 7, 2018
fdda995
Add test
sakapon Apr 7, 2018
2e79190
Remove test
sakapon Apr 7, 2018
8ba6f91
Add error page
sakapon Apr 7, 2018
c229f4d
Version up
sakapon Apr 7, 2018
24eef18
Update README.md
sakapon Apr 7, 2018
fe7da6a
Update README.md
sakapon Apr 7, 2018
f93e64d
Update README.md
sakapon Apr 7, 2018
10ac81b
Create README.md
sakapon Apr 7, 2018
fd70393
Update description
sakapon Apr 8, 2018
2d1daf3
Merge branch 'v2.0' of https://github.com/sakapon-net/Random-Data-Web…
sakapon Apr 8, 2018
a524855
Update README.md
sakapon Apr 8, 2018
adc5c75
Update README.md
sakapon Apr 8, 2018
b9622f1
Update README.md
sakapon Apr 8, 2018
b84ce82
Update README.md
sakapon Apr 8, 2018
84655ab
Update README.md
sakapon Apr 8, 2018
f16e18c
Update Hosting.md
sakapon Apr 8, 2018
f05dabe
Update Deployment.md
sakapon Apr 8, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,35 @@
# Random Data Web API
Provides the JSON/JSONP API to generate random data.
Provides the JSON Web API to generate random data.
This Web API supports CORS (Cross-Origin Resource Sharing).

Using PaaS is the simplest way to host this Web API.
For example, if you fork this repository, you can deploy directly the Web API to an Azure Web App by the Microsoft Azure Portal.
In this case, the continuous deployment is configured.

[日本語のドキュメント](docs)

## Random Data
- alphabets
- alphanumerics
- byte sequence
- UUID (GUID)
- time-ordered ID

## Web App
This project is actually the ASP.NET Web app that contains the following:
- Web API
- help page with specification
- test page using jQuery

[randomdata.azurewebsites.net](https://randomdata.azurewebsites.net/) is a sample deployment.

### Development Environment
- .NET Framework 4.5
- ASP.NET Web API 5.2.3
- ASP.NET Web API Help Page 5.2.3
- ASP.NET Web API Cross-Origin Support 5.2.3
- [Blaze 1.1.10](https://github.com/sakapon/Blaze)

### Release Notes
- **v1.0.0** The first release, using ASP.NET MVC.
- **v2.0.6** Use ASP.NET Web API.
31 changes: 31 additions & 0 deletions RandomData2/RandomData2.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27428.2015
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RandomDataWebApi", "RandomDataWebApi\RandomDataWebApi.csproj", "{A62DF1CA-11D0-427E-91CB-C08281D3DE7C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTest", "UnitTest\UnitTest.csproj", "{43896562-E647-4F9E-8498-8542FCA26834}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A62DF1CA-11D0-427E-91CB-C08281D3DE7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A62DF1CA-11D0-427E-91CB-C08281D3DE7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A62DF1CA-11D0-427E-91CB-C08281D3DE7C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A62DF1CA-11D0-427E-91CB-C08281D3DE7C}.Release|Any CPU.Build.0 = Release|Any CPU
{43896562-E647-4F9E-8498-8542FCA26834}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{43896562-E647-4F9E-8498-8542FCA26834}.Debug|Any CPU.Build.0 = Debug|Any CPU
{43896562-E647-4F9E-8498-8542FCA26834}.Release|Any CPU.ActiveCfg = Release|Any CPU
{43896562-E647-4F9E-8498-8542FCA26834}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {724388ED-9668-4465-8412-8C3C76730BC3}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using System.Web.Http.Cors;

namespace RandomWebApp
namespace RandomDataWebApi
{
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API の設定およびサービス

config.Formatters.Remove(config.Formatters.XmlFormatter);
config.EnableCors(new EnableCorsAttribute("*", "*", "*"));

// Web API ルート
config.MapHttpAttributeRoutes();

config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Text;
using System.Web;
using System.Web.Http.Description;

namespace RandomDataWebApi.Areas.HelpPage
{
public static class ApiDescriptionExtensions
{
/// <summary>
/// Generates an URI-friendly ID for the <see cref="ApiDescription"/>. E.g. "Get-Values-id_name" instead of "GetValues/{id}?name={name}"
/// </summary>
/// <param name="description">The <see cref="ApiDescription"/>.</param>
/// <returns>The ID as a string.</returns>
public static string GetFriendlyId(this ApiDescription description)
{
string path = description.RelativePath;
string[] urlParts = path.Split('?');
string localPath = urlParts[0];
string queryKeyString = null;
if (urlParts.Length > 1)
{
string query = urlParts[1];
string[] queryKeys = HttpUtility.ParseQueryString(query).AllKeys;
queryKeyString = String.Join("_", queryKeys);
}

StringBuilder friendlyPath = new StringBuilder();
friendlyPath.AppendFormat("{0}-{1}",
description.HttpMethod.Method,
localPath.Replace("/", "-").Replace("{", String.Empty).Replace("}", String.Empty));
if (queryKeyString != null)
{
friendlyPath.AppendFormat("_{0}", queryKeyString.Replace('.', '-'));
}
return friendlyPath.ToString();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Uncomment the following to provide samples for PageResult<T>. Must also add the Microsoft.AspNet.WebApi.OData
// package to your project.
////#define Handle_PageResultOfT

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Net.Http.Headers;
using System.Reflection;
using System.Web;
using System.Web.Http;
#if Handle_PageResultOfT
using System.Web.Http.OData;
#endif

namespace RandomDataWebApi.Areas.HelpPage
{
/// <summary>
/// Use this class to customize the Help Page.
/// For example you can set a custom <see cref="System.Web.Http.Description.IDocumentationProvider"/> to supply the documentation
/// or you can provide the samples for the requests/responses.
/// </summary>
public static class HelpPageConfig
{
[SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters",
MessageId = "RandomDataWebApi.Areas.HelpPage.TextSample.#ctor(System.String)",
Justification = "End users may choose to merge this string with existing localized resources.")]
[SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly",
MessageId = "bsonspec",
Justification = "Part of a URI.")]
public static void Register(HttpConfiguration config)
{
// Uncomment the following to use the documentation from XML documentation file.
config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/bin/RandomDataWebApi.xml")));

// Uncomment the following to use "sample string" as the sample for all actions that have string as the body parameter or return type.
// Also, the string arrays will be used for IEnumerable<string>. The sample objects will be serialized into different media type
// formats by the available formatters.
config.SetSampleObjects(new Dictionary<Type, object>
{
{ typeof(int), 8 },
// {typeof(string), "sample string"},
// {typeof(IEnumerable<string>), new string[]{"sample 1", "sample 2"}}
});

// Extend the following to provide factories for types not handled automatically (those lacking parameterless
// constructors) or for which you prefer to use non-default property values. Line below provides a fallback
// since automatic handling will fail and GeneratePageResult handles only a single type.
#if Handle_PageResultOfT
config.GetHelpPageSampleGenerator().SampleObjectFactories.Add(GeneratePageResult);
#endif

// Extend the following to use a preset object directly as the sample for all actions that support a media
// type, regardless of the body parameter or return type. The lines below avoid display of binary content.
// The BsonMediaTypeFormatter (if available) is not used to serialize the TextSample object.
config.SetSampleForMediaType(
new TextSample("Binary JSON content. See http://bsonspec.org for details."),
new MediaTypeHeaderValue("application/bson"));

//// Uncomment the following to use "[0]=foo&[1]=bar" directly as the sample for all actions that support form URL encoded format
//// and have IEnumerable<string> as the body parameter or return type.
//config.SetSampleForType("[0]=foo&[1]=bar", new MediaTypeHeaderValue("application/x-www-form-urlencoded"), typeof(IEnumerable<string>));

//// Uncomment the following to use "1234" directly as the request sample for media type "text/plain" on the controller named "Values"
//// and action named "Put".
//config.SetSampleRequest("1234", new MediaTypeHeaderValue("text/plain"), "Values", "Put");

//// Uncomment the following to use the image on "../images/aspNetHome.png" directly as the response sample for media type "image/png"
//// on the controller named "Values" and action named "Get" with parameter "id".
//config.SetSampleResponse(new ImageSample("../images/aspNetHome.png"), new MediaTypeHeaderValue("image/png"), "Values", "Get", "id");

//// Uncomment the following to correct the sample request when the action expects an HttpRequestMessage with ObjectContent<string>.
//// The sample will be generated as if the controller named "Values" and action named "Get" were having string as the body parameter.
//config.SetActualRequestType(typeof(string), "Values", "Get");

//// Uncomment the following to correct the sample response when the action returns an HttpResponseMessage with ObjectContent<string>.
//// The sample will be generated as if the controller named "Values" and action named "Post" were returning a string.
//config.SetActualResponseType(typeof(string), "Values", "Post");
}

#if Handle_PageResultOfT
private static object GeneratePageResult(HelpPageSampleGenerator sampleGenerator, Type type)
{
if (type.IsGenericType)
{
Type openGenericType = type.GetGenericTypeDefinition();
if (openGenericType == typeof(PageResult<>))
{
// Get the T in PageResult<T>
Type[] typeParameters = type.GetGenericArguments();
Debug.Assert(typeParameters.Length == 1);

// Create an enumeration to pass as the first parameter to the PageResult<T> constuctor
Type itemsType = typeof(List<>).MakeGenericType(typeParameters);
object items = sampleGenerator.GetSampleObject(itemsType);

// Fill in the other information needed to invoke the PageResult<T> constuctor
Type[] parameterTypes = new Type[] { itemsType, typeof(Uri), typeof(long?), };
object[] parameters = new object[] { items, null, (long)ObjectGenerator.DefaultCollectionSize, };

// Call PageResult(IEnumerable<T> items, Uri nextPageLink, long? count) constructor
ConstructorInfo constructor = type.GetConstructor(parameterTypes);
return constructor.Invoke(parameters);
}
}

return null;
}
#endif
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using System.Web.Http;
using System.Web.Mvc;
using RandomDataWebApi.Areas.HelpPage.ModelDescriptions;
using RandomDataWebApi.Areas.HelpPage.Models;

namespace RandomDataWebApi.Areas.HelpPage.Controllers
{
/// <summary>
/// The controller that will handle requests for the help page.
/// </summary>
public class HelpController : Controller
{
private const string ErrorViewName = "Error";

public HelpController()
: this(GlobalConfiguration.Configuration)
{
}

public HelpController(HttpConfiguration config)
{
Configuration = config;
}

public HttpConfiguration Configuration { get; private set; }

public ActionResult Index()
{
ViewBag.DocumentationProvider = Configuration.Services.GetDocumentationProvider();
return View(Configuration.Services.GetApiExplorer().ApiDescriptions);
}

public ActionResult Api(string apiId)
{
if (!String.IsNullOrEmpty(apiId))
{
HelpPageApiModel apiModel = Configuration.GetHelpPageApiModel(apiId);
if (apiModel != null)
{
return View(apiModel);
}
}

return View(ErrorViewName);
}

public ActionResult ResourceModel(string modelName)
{
if (!String.IsNullOrEmpty(modelName))
{
ModelDescriptionGenerator modelDescriptionGenerator = Configuration.GetModelDescriptionGenerator();
ModelDescription modelDescription;
if (modelDescriptionGenerator.GeneratedModels.TryGetValue(modelName, out modelDescription))
{
return View(modelDescription);
}
}

return View(ErrorViewName);
}

public ActionResult JsonTest()
{
return View();
}
}
}
Loading