Skip to content

GetV1 #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 52 commits into
base: v1.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
f2ba4ac
UriPathExtensionMapping now optional, added optional QueryStringMapping
Oct 25, 2013
d70fb80
Update to Web API 2
panesofglass Nov 21, 2013
f76bd8c
Merge pull request #20 from panesofglass/master
ChrisMissal Dec 5, 2013
8644251
version bump
ChrisMissal Dec 5, 2013
1447bff
Cleanup sample web project dependencies.
panesofglass Dec 12, 2013
c12a472
Include NUnit.Runners to fix running tests in the build.
panesofglass Dec 12, 2013
6b4765d
Cleanup formatting in the test files.
panesofglass Dec 12, 2013
0f8bc11
Fix failing test.
panesofglass Dec 12, 2013
e84a940
Move samples to a samples directory.
panesofglass Dec 12, 2013
f0147fc
Change sample web host to use attribute routing.
panesofglass Dec 12, 2013
0db8ba0
Update README
panesofglass Dec 12, 2013
2797677
Update attribute routes to make format an optional parameter.
panesofglass Dec 12, 2013
3dc377b
Clean up sample code.
panesofglass Dec 12, 2013
ae7e7a2
Merge branch 'patch-1' of https://github.com/y0gzah/WebApiContrib.For…
panesofglass Dec 12, 2013
3b803bc
Add in a sample case for retrieving simple JSON.
panesofglass Dec 12, 2013
aaeef92
Merge branch 'patch-1'
panesofglass Dec 12, 2013
680b944
Work on fix for problem with supporting JSON and JSONP from same API.
panesofglass Dec 12, 2013
612e472
Clean up web host sample.
panesofglass Dec 12, 2013
e85a283
Push script into the scripts section of the layout.
panesofglass Dec 12, 2013
77c94e5
Fix order of route registration.
panesofglass Dec 12, 2013
40a6410
Re-apply path extension to enable use of /jsonp in the path and not b…
panesofglass Dec 12, 2013
5cb10f8
Merge branch 'master' of github.com:panesofglass/WebApiContrib.Format…
panesofglass Jan 9, 2014
d928969
Merge pull request #21 from panesofglass/master
panesofglass Jan 9, 2014
3a0b8ec
Remove unused class fields.
panesofglass Jan 9, 2014
25e1694
move to version 2.1
ChrisMissal Jan 9, 2014
a7b7f3b
Fix Verbose warning.
panesofglass Jan 9, 2014
75b1c1a
Fix JSON rendering for invalid JSONP requests.
panesofglass Jan 9, 2014
f1747cf
#23 Get application/json test to fail.
panesofglass Jan 9, 2014
ce745b3
Fixes #23
panesofglass Jan 10, 2014
eb41c06
Add HttpConfigurationExtensions to simplify the addition of the Jsonp…
panesofglass Jan 17, 2014
8a6b509
Address issue raised in #24 to remove other mappings in favor of matc…
panesofglass Jan 17, 2014
cebc5bd
Merge pull request #25 from panesofglass/conneg
panesofglass Jan 23, 2014
05fefb2
move to version 3.0
ChrisMissal Feb 25, 2014
d8b95bf
Update WebApiContrib.Formatting.Jsonp.nuspec
ChrisMissal Feb 25, 2014
5522e37
Remove useless dependencies (like System.Web) from Jsonp formatter/te…
Feb 11, 2015
c9a4b54
Merge pull request #35 from vba/no_system_web
panesofglass Feb 11, 2015
dbbd8dd
Added additional notes for how to use the formatter #33
panesofglass Mar 12, 2015
1f85537
Migrate projects from nuget to paket
Mar 13, 2015
eea470a
Remove useless references from the main project
Mar 13, 2015
7498eb3
Add fake build script and fill it with trivial tasks such as build / …
Mar 13, 2015
4952dc0
Add an ability to push and package nuget packages
Mar 16, 2015
3f81e46
Fix for Rosetta Flash JSONP vulnerability #38
panesofglass May 29, 2015
ec095ce
Merge pull request #39 from WebApiContrib/rosetta-flash
panesofglass May 29, 2015
7e6ecdb
Add sanitation for callback parameter
Jun 25, 2015
be881ed
various cleanup tasks
Jun 25, 2015
48a124b
Merge pull request #42 from puco/cleanup
panesofglass Jun 26, 2015
ed59cba
Merge branch 'sanitation' of https://github.com/puco/WebApiContrib.Fo…
tachyus-ryan Jun 26, 2015
8977fc9
Merge branch 'paket_fake_integration' of https://github.com/vba/WebAp…
tachyus-ryan Jun 26, 2015
5adbc22
chore: fix hint paths in tests project file
Jul 29, 2015
169f779
Merge pull request #43 from puco/master
ChrisMissal Jul 29, 2015
dce0e57
correct project references
ChrisMissal Aug 12, 2015
38f7739
Merge pull request #44 from WebApiContrib/reference-fixes
ChrisMissal Aug 12, 2015
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Thumbs.db
*.ilk
*.log
*.ncrunch*
.nuget/
[Bb]in
[Dd]ebug*/
*.lib
Expand All @@ -39,3 +40,4 @@ script.sql
*.ncrunchsolution
*.ncrunchproject
*.nupkg
.paket/paket.exe
6 changes: 0 additions & 6 deletions .nuget/NuGet.Config

This file was deleted.

139 changes: 0 additions & 139 deletions .nuget/NuGet.targets

This file was deleted.

Binary file removed .nuget/nuget.exe
Binary file not shown.
Binary file added .paket/paket.bootstrapper.exe
Binary file not shown.
38 changes: 38 additions & 0 deletions .paket/paket.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- Enable the restore command to run before builds -->
<RestorePackages Condition=" '$(RestorePackages)' == '' ">true</RestorePackages>
<!-- Download Paket.exe if it does not already exist -->
<DownloadPaket Condition=" '$(DownloadPaket)' == '' ">true</DownloadPaket>
<PaketToolsPath>$(MSBuildThisFileDirectory)</PaketToolsPath>
<PaketRootPath>$(MSBuildThisFileDirectory)..\</PaketRootPath>
</PropertyGroup>
<PropertyGroup>
<!-- Paket command -->
<PaketExePath Condition=" '$(PaketExePath)' == '' ">$(PaketToolsPath)paket.exe</PaketExePath>
<PaketBootStrapperExePath Condition=" '$(PaketBootStrapperExePath)' == '' ">$(PaketToolsPath)paket.bootstrapper.exe</PaketBootStrapperExePath>
<PaketCommand Condition=" '$(OS)' == 'Windows_NT'">"$(PaketExePath)"</PaketCommand>
<PaketCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 $(PaketExePath)</PaketCommand>
<PaketBootStrapperCommand Condition=" '$(OS)' == 'Windows_NT'">"$(PaketBootStrapperExePath)"</PaketBootStrapperCommand>
<PaketBootStrapperCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 $(PaketBootStrapperExePath)</PaketBootStrapperCommand>
<!-- Commands -->
<PaketReferences Condition="!Exists('$(MSBuildProjectFullPath).paket.references')">$(MSBuildProjectDirectory)\paket.references</PaketReferences>
<PaketReferences Condition="Exists('$(MSBuildProjectFullPath).paket.references')">$(MSBuildProjectFullPath).paket.references</PaketReferences>
<RestoreCommand>$(PaketCommand) restore --references-files "$(PaketReferences)"</RestoreCommand>
<DownloadPaketCommand>$(PaketBootStrapperCommand)</DownloadPaketCommand>
<!-- We need to ensure packages are restored prior to assembly resolve -->
<BuildDependsOn Condition="$(RestorePackages) == 'true'">RestorePackages; $(BuildDependsOn);</BuildDependsOn>
</PropertyGroup>
<Target Name="CheckPrerequisites">
<!-- Raise an error if we're unable to locate paket.exe -->
<Error Condition="'$(DownloadPaket)' != 'true' AND !Exists('$(PaketExePath)')" Text="Unable to locate '$(PaketExePath)'" />
<MsBuild Targets="DownloadPaket" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT;DownloadPaket=$(DownloadPaket)" />
</Target>
<Target Name="DownloadPaket">
<Exec Command="$(DownloadPaketCommand)" Condition=" '$(DownloadPaket)' == 'true' AND !Exists('$(PaketExePath)')" />
</Target>
<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(RestoreCommand)" WorkingDirectory="$(PaketRootPath)" Condition="Exists('$(PaketReferences)')" />
</Target>
</Project>
17 changes: 17 additions & 0 deletions Build.proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Root>$(MSBuildThisFileDirectory)</Root>
<SolutionDir>$(Root)</SolutionDir>
</PropertyGroup>
<Target Name="InstallNuGet">
<MakeDir Directories="$(Root)/.nuget" />
<MSBuild Projects="$(Root)/.nuget/NuGet.targets"
Properties="DownloadNuGetExe=true;ProjectDir=$(Root);SolutionDir=$(Root)"
Targets="RestorePackages" />
</Target>
<Target Name="Build" DependsOnTargets="InstallNuGet">
<Exec Command="tools\psake\psake.bat"
WorkingDirectory="$(Root)"
LogStandardErrorAsError="true" />
</Target>
</Project>
41 changes: 18 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,32 @@ WebApiContrib.Formatting.Jsonp

In order to add it to your Web API solution, run `Install-Package WebApiContrib.Formatting.Jsonp` from your NuGet Package Manager console in Visual Studio.

To use the `JsonpMediaTypeFormatter`, add the following code to your Web API Configuration:
To use the `JsonpMediaTypeFormatter`, add the following code to your configuration in Global.asax.cs:

`FormatterConfig.RegisterFormatters(GlobalConfiguration.Configuration.Formatters);`
`GlobalConfiguration.Configuration.AddJsonpFormatter();`

The `FormatterConfig` class looks this:
You can specify a `MediaTypeFormatter` and callback parameter name as optional parameters. By default, the `JsonpMediaTypeFormatter` will use the `config.Formatters.JsonFormatter` and `callback` as default values.

public class FormatterConfig
{
public static void RegisterFormatters(MediaTypeFormatterCollection formatters)
{
var jsonFormatter = formatters.JsonFormatter;
jsonFormatter.SerializerSettings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
You should specify `text/javascript` the media type to accept in the request's `Accept` header. If you leave this out, the client may receive `application/json` as the default `JsonMediaTypeFormatter` will likely handle the request. In other words, the `Accept` header is used as the means to signal Web API to use the `JsonpMediaTypeFormatter`. For example, in JQuery, you would write:

// Insert the JSONP formatter in front of the standard JSON formatter.
var jsonpFormatter = new JsonpMediaTypeFormatter(formatters.JsonFormatter);
formatters.Insert(0, jsonpFormatter);
}
}
``` javascript
$.ajax({
type: "GET",
url: "/jsonp-endpoint?callback=callme",
contentType: "text/javascript",
// ...
});
```

After that, update your Default ASP.NET Web API route in `/App_Start/RouteConfig.cs`:
The `JsonpMediaTypeFormatter` will then match the specified callback parameter name from the request URI, e.g. `?callback=?`.

routes.MapHttpRoute(
If you are using traditional routing, update your Default ASP.NET Web API route in `/App_Start/WebApiConfig.cs`:

config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}/{format}",
defaults: new { id = RouteParameter.Optional, format = RouteParameter.Optional }
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);

Now you should be able to issue JSONP requests against your Web API.

To see the `JsonpMediaTypeFormatter` in action, just clone this project, run the `WebContribContrib.Formatting.Jsonp.SampleWebHost` project web application, and then start the `WebApiContrib.Formatting.Jsonp.SampleJQueryClient` web application and hit the "Get JSONP" button.

3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### New in 3.0.1 (Released 2015-03-13)
* Suppression of useless references to System.Web
* Internal paket/fake integration
35 changes: 24 additions & 11 deletions WebApiContrib.Formatting.Jsonp.sln
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiContrib.Formatting.Jsonp", "src\WebApiContrib.Formatting.Jsonp\WebApiContrib.Formatting.Jsonp.csproj", "{CD617362-8723-4592-A3B3-D2FBEF645CD2}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{B0465E1E-C558-4A08-BD29-512DD3699FEF}"
ProjectSection(SolutionItems) = preProject
.nuget\NuGet.Config = .nuget\NuGet.Config
.nuget\nuget.exe = .nuget\nuget.exe
.nuget\NuGet.targets = .nuget\NuGet.targets
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebContribContrib.Formatting.Jsonp.SampleWebHost", "src\WebApiContrib.Formatting.Jsonp.SampleWebHost\WebContribContrib.Formatting.Jsonp.SampleWebHost.csproj", "{2BB842CA-1B0D-4405-80D0-CF87702F6310}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebContribContrib.Formatting.Jsonp.SampleWebHost", "samples\WebApiContrib.Formatting.Jsonp.SampleWebHost\WebContribContrib.Formatting.Jsonp.SampleWebHost.csproj", "{2BB842CA-1B0D-4405-80D0-CF87702F6310}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiContrib.Formatting.Jsonp.SampleJQueryClient", "src\WebApiContrib.Formatting.Jsonp.SampleJQueryClient\WebApiContrib.Formatting.Jsonp.SampleJQueryClient.csproj", "{05EA8FD1-BBA8-49FD-AF7F-2B991A80B53E}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiContrib.Formatting.Jsonp.SampleJQueryClient", "samples\WebApiContrib.Formatting.Jsonp.SampleJQueryClient\WebApiContrib.Formatting.Jsonp.SampleJQueryClient.csproj", "{05EA8FD1-BBA8-49FD-AF7F-2B991A80B53E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiContrib.Formatting.Jsonp.Tests", "test\WebApiContrib.Formatting.Jsonp.Tests\WebApiContrib.Formatting.Jsonp.Tests.csproj", "{A6233026-A0E5-43A5-83CB-356603DF9BBC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{BDE1485B-1DF1-464C-AFE4-B8547E6E83F9}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".paket", ".paket", "{BC242EA9-8B64-40B8-8536-CA5896423A19}"
ProjectSection(SolutionItems) = preProject
paket.dependencies = paket.dependencies
paket.lock = paket.lock
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{B70D0BEB-53C2-4B8C-A275-C3E15BF795CB}"
ProjectSection(SolutionItems) = preProject
build.cmd = build.cmd
build.fsx = build.fsx
paket.template = paket.template
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -42,4 +51,8 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{2BB842CA-1B0D-4405-80D0-CF87702F6310} = {BDE1485B-1DF1-464C-AFE4-B8547E6E83F9}
{05EA8FD1-BBA8-49FD-AF7F-2B991A80B53E} = {BDE1485B-1DF1-464C-AFE4-B8547E6E83F9}
EndGlobalSection
EndGlobal
2 changes: 0 additions & 2 deletions build.bat

This file was deleted.

20 changes: 20 additions & 0 deletions build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

@echo off
cls

.paket\paket.bootstrapper.exe
if errorlevel 1 (
exit /b %errorlevel%
)

.paket\paket.exe restore
if errorlevel 1 (
exit /b %errorlevel%
)

IF NOT EXIST build.fsx (
.paket\paket.exe update
packages\FAKE\tools\FAKE.exe init.fsx
)

packages\FAKE\tools\FAKE.exe build.fsx %*
Loading