Git Product home page Git Product logo

webapicontrib's Introduction

WebAPIContrib

WebAPIContrib is a collection of open source projects to help improve your work with ASP.NET Web API. We have divided the projects into a few different categories. For more information on each project, click through to visit the GitHub page.

Core

  • WebApiContrib Build Status
  • WebApiContrib.Testing

Formatters

Inversion of Control

Tracing

Miscellaneous


Contributing

If you would like to contribute, feel free to fork the projects or get in touch with the mailing list: https://groups.google.com/group/webapicontrib

Want to transfer your project to WebApiContrib?

You created your own project and now want to transfer it to WebApiContrib? Awesome! We've got you covered. It is easy peasy.

webapicontrib's People

Contributors

abatishchev avatar alexzeitler avatar aliostad avatar andreabalducci avatar carolynvs avatar chrismissal avatar cvbarros avatar darrelmiller avatar filipw avatar glennblock avatar jordangray avatar kenegozi avatar kurtschindler avatar lugoues avatar maartenba avatar panesofglass avatar pedroreys avatar prettycode avatar rdingwall avatar ryanande avatar tachyus-ryan avatar terravenil avatar tugberkugurlu avatar victor-alexiev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

webapicontrib's Issues

Plans to support Sync framework

Are there any plans to support MS sync framework through HTTP using the Web Api ...
I think it would be a great addition ... probably already there but I have no idea ...

It would be a great addition to sync folders and files over http between diverse machines.

ElmahAggregateExceptionLogger

I found this extension to ElmahExceptionLogger useful:

public class ElmahAggregateExceptionLogger : Elmah.Contrib.WebApi.ElmahExceptionLogger
{
    public override void Log(ExceptionLoggerContext context)
    {
        var aggregateException = context.Exception as AggregateException;
        if (aggregateException != null)
        {
            context = new ExceptionLoggerContext(new ExceptionContext(aggregateException.GetBaseException(), context.CatchBlock));
        }
        base.Log(context);
    }
}

It decreases exception nesting by one in case of AggregateException has been thrown.

Will you accept a pull request?

UnderscoreMappingResolver

I didn't find in the project anything similar to this:

class UnderscoreMappingResolver : Newtonsoft.Json.Serialization.DefaultContractResolver

Will you accept a push request?

Push latest to NuGet

The most recent nuget package was on Nov, 2013. Since that there we many commits. Please publish an new one. Should be easy.

CSVMediaTypeFormatter

In the CSVMediaTypeFormatter there is a small problem where the StreamWriter is not closing the stream resulting in the last chunk of data going missing.

This is easy to resolve, simply replace:

var streamWriter = new StreamWriter(stream);
streamWriter.Write(stringWriter.ToString());

with:

using (StreamWriter streamWriter = new StreamWriter(stream))
{
    streamWriter.Write(stringWriter.ToString());
}

Chris

ApiController cannot extend another class

Before updating to the latest version (5.1.2) my controllers extended a base class like so:

public class ProcessController : AProtectedReadModelController
public class AProtectedReadModelController : ApiController

now the controllers extending that class are not found anymore, they are resolved using AutoFac Web Api thus I am not sure whether this is a web api issue.

Create separate projects for separate concerns

Have 1 project per concern instead of a single proj files with concerns separated in namespaces.

Example:

WebApiContrib.MessageHandlers.csproj
WebApiContrib.MessageFormatters.csproj
WebApiContrib.ResponseMessages.csproj

I'm still not sure if this is the way to go, but my goal with this separation is to be able to create fine grained nuget packages.

Move Samples to a separate repository

Samples would work better if the samples pulled the various WebApiContrib packages from nuget.org. This would have the benefit of allowing us to verify both functionality in use as well as our packaging strategy.

ShouldMapTo url parameters not being recognized

Right now I'm trying to pass multiple parameters to the action MyRecentActivity, but when I run the test below, an exception is thrown saying that the first parameter was 0, while it was expecting 1. This the method it should be mapping to:

public Result MyRecentActivity(int offset = 1, int limit = 15){}. 

Could you shed some light on the problem

const string url = "~/MobileServices/Dashboard/Tickets/my_recent_activity/1?limit=15";
url.ShouldMapTo<TicketsController>(x => x.MyRecentActivity(1, 15), "GET");

CacheHandler vs CacheCow

I've been reading that CacheCow project has run with the CacheHandler code from this project and that this CacheHandler is not longer being enhanced. It's a big source of confusion! Would it be feasible to remove CacheHandler from this project?

Review features to keep in the contrib

On the move from the beta to rc bits a lot of things had to be fixed (thanks @panesofglass) and it got me thinking that we might need to prune the feature-set of the contrib.

For example, we have some features based on blog posts, like the ReadWriteFormUrlEncodedFormatter. This formatter is based on a blog post by Carlos Figueira to support the scenario of "an API which needs to invoke an existing service which doesn’t support JSON input, and supports only forms data instead".

As he mentions in the blog post:

I haven’t been able to find any formal specification for the format used by jQuery when encoding complex types, so this is what I was able to find out from passing many different object types and observing what their wire representation was. In other words, it works on my machine.

As an experiement this is great, but keeping it on the Contrib means that we will have to support it, write the docs, etc, as it's included in the WebApiContrib nuget package.

Besides the cost of maintaining the features, onne other concern I have with the code pulled from blog posts is with licensing. For example the code from the blog post is distributed with an Apache v.2 license. Thus we should be also including a copy of the Apache v.2 license, but we use MIT to license the contrib. I'm not an OSS license expert at all, but I believe we are infringing the Apache license by pulling the code without pulling the license text. I'm not sure just the comment referencing the blog post is enough.

With all that said, after we are done with the rc bits, I suggest we review the codebase and make sure we only keep what we can, due to licensing, and what we are willing to maintain and ship as production ready code.

CommonServiceLocator Nuget Dependency Is Not Needed

Its referenced in the:

WebApiContrib.Testing/packages.config

But nowhere in the code is: Microsoft.Practices.ServiceLocation.dll actually referenced.

Can be safely removed?
Its dragging an unnecessary dependency around.

Add StructureMap Resolver

Just dropping an issue here ---> [x] <--- so I don't have a out of the blue drive by pull request ... yeah or nay?

WebApiContrib.Testing dependency on WebApiContrib

Hi folks,

It looks as though WebApiContrib.Testing should list WebApiContrib as a dependency.

When running tests depending on WebApiContrib.Testing (and not WebApiContrib) via TeamCity (MSTest):

Unable to load the test container '\WebApiContrib.Testing.dll' or one of its dependencies. Error details: System.IO.FileNotFoundException: Could not load file or assembly 'WebApiContrib, Version=0.9.10.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

Similarly, when running tests with MSTest at the command line locally, I receive the following warning:

Warning: Test Run deployment issue: The assembly or module 'WebApiContrib' directly or indirectly referenced by the test container '' was not found.

Having a thumb around the WebApiContrib sln, there's a project reference from WebApiContrib.Testing to WebApiContrib. It feels like this all implies there should be a dependency via nuget--what are your thoughts?

I've managed to work around the TeamCity issue by referencing WebApiContrib (which isn't actually used), and specifically choosing a version match with WebApiContrib.Testing.

Thanks in advance!

Matt.

MVC Style Bindings - Multiple actions were found ERROR

If I have a controller with two GET actions - e.g /api/get and /api/get/:id, when I add [MvsStyleBinding] to my controller, I get the following error:

An error has occurred.
ExceptionMessage: Multiple actions were found that match the request: 
Get on type MvcStyleBindingProblem.ValuesController
GetById on type MvcStyleBindingProblem.ValuesController
ExceptionType:System.InvalidOperationException
StackTrace:  at System.Web.Http.Controllers.ApiControllerActionSelector.ActionSelectorCacheItem.SelectAction(HttpControllerContext controllerContext)
   at System.Web.Http.Controllers.ApiControllerActionSelector.SelectAction(HttpControllerContext controllerContext)
   at System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)
   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()

I have a very simple api project here demonstrating the problem:
https://github.com/freeranger/MvcStyleBindingProblem

If I remove the[MvcStyleBinding] then the error goes away but obviously the whole point is to actually use it ;)

LoggingHandler questions

Hi all,

there are two questions I have regarding the LoggingHandler class:

a) I would like to modify it, such that the ILoggingRepository.Log() method is only called once for each request, i.e. when the response has been generated. I would obviously have to modify the code a bit; changing the ApiLoggingInfo class such that it has fields both for the request body and for the response body etc. Are there any issues that prevent this from working? For instance, will there be occasions where the request can be logged, but no response? Or anything else?

b) I would also like to add information about the currently logged in user to the logging. Is there anything which prevents me from adding this? (I.e. does the authentication perhaps happen further down the line?)

Regards,
Daníel

Null reference with Caching Handler

Hi,
I'm trying to use the caching handler and it works fine if I use the e-tag and the If-None-Match.

The problem is about If-Modified-Since.
Everytime I try to specify something like that

"If-Modified-Since" = "Thu, 01 Jan 1970 00:00:00 GMT";

I got a null exception here:

return isModified ^ ifModified && actualEtag != null
? new NotModifiedResponse(actualEtag.ToEntityTagHeaderValue()).ToTask()
: null;

It happens because actualEtag is null.

Any Idea?

WebAPI Contrib caching fails on first call

In my project, I installed WebApiContrib from Nuget onto a webapi project. All I did was this:

GlobalConfiguration.Configuration.MessageHandlers.Add(new WebApiContrib.Caching.CachingHandler());

After that deployed it on our server, and this exception would randomly pop up on google chrome:

[NullReferenceException: Object reference not set to an instance of an object.]
WebApiContrib.Caching.CachingHandler.<GetIfModifiedUnmodifiedSince>b__32(HttpRequestMessage request) +951
WebApiContrib.Caching.<>c__DisplayClass12.<SendAsync>b__11(Func`2 r) +21
System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source, Func`2 predicate) +168
WebApiContrib.Caching.CachingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) +255
System.Web.Http.HttpServer.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) +254
System.Net.Http.HttpMessageInvoker.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) +78
System.Web.Http.WebHost.HttpControllerHandler.BeginProcessRequest(HttpContextBase httpContextBase, AsyncCallback callback, Object state) +286
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +12551795
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288

Trying to debug further what's causing this - but meanwhile, any ideas appreciated.

EDIT 1:
Okay, it appears to only occur on the first call after the application pool has gone down and is started on the request you make. What exactly is happening is very hard to debug, because I cannot attach a debugger to a process that is not running.

Console/HttpClient for Contact Manager

We are trying to use WebApi for communication between our in house applications using HttpClient. We had everything working until the RC and that broke everything. Do you have a sample application that uses HttpClient and not just javascript/jquery example?

Can't get the MvcActionValueBinder to work with json body?

I'm getting an exception in the MvcActionBinding class at this line:

FormDataCollection fd = content.ReadAsAsync<FormDataCollection>().Result;

Here is my controller method:

[Route("{accountId:int}/creditlimit")]
[HttpPut]
public async Task<IHttpActionResult> UpdateAccountCreditLimit(int accountId, [FromBody] UpdateAccountCreditLimitRequest request)

Here is the endpoint I'm calling in postman:

http://localhost:53367/api/accounts/47358/creditlimit

wtih a application/json body (trimmed for brevity) that looks like this:

{
  "creditLimit": 125000.00
}

As you can see, I'm trying to get the accountId from the uri and the request object from the body. The exception I get is a System.AggregateException

{"Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Net.Http.Formatting.FormDataCollection' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.\r\nTo fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.\r\nPath 'creditLimit', line 2, position 19."}

How can I use the custom model binder with json body?

How to register routes for Testing WebApi routes (WebApiContrib.Testing)?

Probably this topic was described before but I could not find a solution.

There are two ways to registrate routes in MVC and WebApi projects:

  1. MVC Project you call RouteConfig.RegisterRoutes( RouteTable.Routes ) which adds routes into routes table. This way is used in your example (here: http://www.carolynvanslyck.com/blog/2013/01/webapi-route-testing/)
  2. WebApi Project by default use GlobalConfiguration.Configure( WebApiConfig.Register ). The following example shows how to register routes in unit tests file.
private HttpConfiguration _config;
[SetUp]
public void BeforeEach()
{
    _config = new HttpConfiguration();
    WebApiConfig.Register( _config );
    _config.EnsureInitialized();  // we need to call this method after all other initialization code.
}

The problem that your framework is using RouteTable to check routes. If I register routes in second way then RouteTable would be empty and route tests also would fails.

Could you please provide some link or explanation how to register WebApi routes without moving code into RouteTable.Routes method?
I'm not sure that you understand me so please ask a questions if you want.
Thanks in advance!

add .gitattributes to define core.autocrlf settings

we need to define how we are going to set line endings for the repo. I usually set it to false, as this is the most common option with all the .net repos out there.

But, aspnetwebstack set it to true.

What option do you prefer?

I can commit a .gitattributes file once we set on which option to use.

LoggingHandler causing unobserved task exceptions

The logging handler is unfortunately causing serious errors at some points in time. I'm not exactly sure what is causing the error as it never happens in my testing. Here's a dump from the event log.

An unhandled exception occurred and the process was terminated.

Exception: System.AggregateException

Message: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread.

StackTrace: at System.Threading.Tasks.TaskExceptionHolder.Finalize()

InnerException: System.AggregateException

Message: One or more errors occurred.

StackTrace: at System.Threading.Tasks.Task1.get_Result() at WebApiContrib.MessageHandlers.LoggingHandler.<>c__DisplayClass3.<LogRequestLoggingInfo>b__1(Task1 task)
at System.Threading.Tasks.Task.Execute()

InnerException: System.NullReferenceException

Message: Object reference not set to an instance of an object.

StackTrace: at System.IO.Stream.EndRead(IAsyncResult asyncResult)
at System.Net.Http.StreamToStreamCopy.BufferReadCallback(IAsyncResult ar)

Add documentation in the wiki for what we currently have

In order to people start using all the different extensions that are part of the WebAPIContrib, they need to be able to know that the extension exist, what it does and how to use it.

We can start by documenting in the Wiki what we currently have: formatters. handlers, filters, IoC helpers etc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.