Git Product home page Git Product logo

framework's Introduction

Feather HTTP

feedz.io

A lightweight low ceremony APIs for .NET Core applications.

  • Built on the same primitives as .NET Core
  • Optimized for building HTTP APIs quickly
  • Take advantage of existing .NET Core middleware and frameworks

Hello World

using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;

var app = WebApplication.Create(args);

app.MapGet("/", async http =>
{
    await http.Response.WriteAsync("Hello World");
});

await app.RunAsync();

Tutorial

The tutorial will walk you through building an HTTP API for a todo application using FeatherHttp.

Using CI Builds

To use the dotnet new template, use the following command

dotnet new -i FeatherHttp.Templates::{version} --nuget-source https://f.feedz.io/featherhttp/framework/nuget/index.json

Once you've installed the template, run:

dotnet new feather -n {name}

This will create a new project using FeatherHttp.

To use CI builds add the following nuget feed:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <packageSources>
        <clear />
        <add key="featherhttp" value="https://f.feedz.io/featherhttp/framework/nuget/index.json" />
        <add key="NuGet.org" value="https://api.nuget.org/v3/index.json" />
    </packageSources>
</configuration>

See the list of versions

framework's People

Contributors

alsami avatar clarkezone avatar damianedwards avatar daniel-packard avatar davidfowl avatar robotoptimist 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

framework's Issues

Use with Open API

Trying to add a simple Open API integration:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddSwaggerGen(c =>
{
    c.SwaggerDoc("v1", new OpenApiInfo { Title = "WebApi", Version = "v1" });
});

var app = builder.Build();

app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebApi v1"));

System.AggregateException: 'Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Swashbuckle.AspNetCore.Swagger.ISwaggerProvider Lifetime: Transient ImplementationType: Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator': Unable to resolve service for type 'Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionGroupCollectionProvider' while attempting to activate 'Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator'.) (Error while validating the service descriptor 'ServiceType: Microsoft.Extensions.ApiDescriptions.IDocumentProvider Lifetime: Singleton ImplementationType: Microsoft.Extensions.ApiDescriptions.DocumentProvider': Unable to resolve service for type 'Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionGroupCollectionProvider' while attempting to activate 'Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator'.)'

Feature request: Make StartServerAsync an instance method

I had a look at the example from the Readme and I think it looks quite nice!
I also would like to propose a small change: Make the StartServerAsync an instance method.
This would simplify the API a bit and one could use it like this:
var server = await app.StartServerAsync("http://localhost:3000");.

Q: WebApplication multiple protocol/port/address binding/routing (multihoming)

is it possible to have a single instance of WebApplication bind/listen to different ports and route to different protocols and/or controllers/signalr/grpc services. ie.

a WebApplication listening on port 80/433 that routes to HTTP controllers
the same WebApplication instance also listens on 3000 routing to GRPC service
with a SignalR hub listening on port 8080

the use case for this is a microservice that exposes the same functionality over different ports and/or addresses; instead of having to deploy a service multiple times with differing code for each protocol.

Feather template missing from list post installation

Environment
Windows 10
dotnet sdk - 6.0.100-preview.3.21154.16
Scenario - User installs Feather template in one windows terminal then tries creating a Feather App in windows terminal tab.

Install / tab 1
Templates is installed
image

Create a feather app/ tab2
Try to create a new feather app and the template is not found and not listed.

image

What I did do was just reinstall the template.

Unable to dockerize simple example

error MSB4018 is likely masking a package restore error for featherhttp. It's restoring OK in my linux based CI/CD pipeline for the repo so not sure why there is a problem.

Repro Steps

  1. git clone https://github.com/clarkezone/featherservicetest
  2. cd src\BasicService
  3. docker build -t featherbasicservice .

Result:
PS C:\src\github.com\clarkezone\featherservicetest\src\BasicService> docker build -t cool .
[+] Building 1.6s (18/20)
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 764B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:5.0 0.2s
=> [internal] load metadata for mcr.microsoft.com/dotnet/sdk:5.0 0.2s
=> [stage-1 1/3] FROM mcr.microsoft.com/dotnet/aspnet:5.0@sha256:891da1ae4f8886a05ce3ea23cb5d3099aebcf05e67cc457ceee044442f8f4bce 0.0s
=> [build 1/12] FROM mcr.microsoft.com/dotnet/sdk:5.0@sha256:84cf7fdb35c9d2498db2292528af42bfdc4a34add689086abaed8dac4623d5d5 0.0s
=> [internal] load build context 0.2s
=> => transferring context: 3.37MB 0.2s
=> CACHED [build 2/12] WORKDIR /source 0.0s
=> CACHED [build 3/12] COPY .sln . 0.0s
=> CACHED [build 4/12] COPY BasicService/
.csproj ./BasicService/ 0.0s
=> CACHED [build 5/12] COPY GreeterLogic/.csproj ./GreeterLogic/ 0.0s
=> CACHED [build 6/12] COPY GreeterLogic.Tests/
.csproj ./GreeterLogic.Tests/ 0.0s
=> CACHED [build 7/12] RUN dotnet restore 0.0s
=> [build 8/12] COPY BasicService/. ./BasicService/ 0.0s
=> [build 9/12] COPY GreeterLogic/. ./GreeterLogic/ 0.0s
=> [build 10/12] COPY GreeterLogic.Tests/. ./GreeterLogic.Tests/ 0.0s
=> [build 11/12] WORKDIR /source/BasicService 0.0s
=> ERROR [build 12/12] RUN dotnet publish -c release -o /app --no-restore 0.9s

[build 12/12] RUN dotnet publish -c release -o /app --no-restore:
#19 0.432 Microsoft (R) Build Engine version 16.9.0+57a23d249 for .NET
#19 0.432 Copyright (C) Microsoft Corporation. All rights reserved.
#19 0.432
#19 0.837 /usr/share/dotnet/sdk/5.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: The "ResolvePackageAssets" task failed unexpectedly. [/source/BasicService/BasicService.csproj]
#19 0.837 /usr/share/dotnet/sdk/5.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: NuGet.Packaging.Core.PackagingException: Unable to find fallback package folder 'C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages'. [/source/BasicService/BasicService.csproj]
#19 0.837 /usr/share/dotnet/sdk/5.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at NuGet.Packaging.FallbackPackagePathResolver..ctor(String userPackageFolder, IEnumerable1 fallbackPackageFolders) [/source/BasicService/BasicService.csproj] #19 0.837 /usr/share/dotnet/sdk/5.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.NET.Build.Tasks.NuGetPackageResolver..ctor(String userPackageFolder, IEnumerable1 fallbackPackageFolders) [/source/BasicService/BasicService.csproj]
#19 0.837 /usr/share/dotnet/sdk/5.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.NET.Build.Tasks.NuGetPackageResolver.CreateResolver(IEnumerable`1 packageFolders) [/source/BasicService/BasicService.csproj]
#19 0.837 /usr/share/dotnet/sdk/5.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.NET.Build.Tasks.NuGetPackageResolver.CreateResolver(LockFile lockFile) [/source/BasicService/BasicService.csproj]
#19 0.837 /usr/share/dotnet/sdk/5.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter..ctor(ResolvePackageAssets task) [/source/BasicService/BasicService.csproj]
#19 0.837 /usr/share/dotnet/sdk/5.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader.CreateReaderFromDisk(ResolvePackageAssets task, Byte[] settingsHash) [/source/BasicService/BasicService.csproj]
#19 0.837 /usr/share/dotnet/sdk/5.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader..ctor(ResolvePackageAssets task) [/source/BasicService/BasicService.csproj]
#19 0.837 /usr/share/dotnet/sdk/5.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ReadItemGroups() [/source/BasicService/BasicService.csproj]
#19 0.837 /usr/share/dotnet/sdk/5.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ExecuteCore() [/source/BasicService/BasicService.csproj]
#19 0.837 /usr/share/dotnet/sdk/5.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.NET.Build.Tasks.TaskBase.Execute() [/source/BasicService/BasicService.csproj]
#19 0.837 /usr/share/dotnet/sdk/5.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/source/BasicService/BasicService.csproj]
#19 0.837 /usr/share/dotnet/sdk/5.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/source/BasicService/BasicService.csproj]


executor failed running [/bin/sh -c dotnet publish -c release -o /app --no-restore]: exit code: 1
PS C:\src\github.com\clarkezone\featherservicetest\src\BasicService>

Add way to create a WebApplication without the defaults

Maybe we need 2 overloads:

  • WebApplication.CreateBuilder - Less stuff? console logger and no configuration providers.
  • WebApplication.CreateDefaultBuilder - What we have today

OR do we do nothing and require users to clear logging and configuration providers.

[Bug] Call to AddHttpClient() on WebApplicationBuilder.Services override serilog logging with default logging

Self explanatory, here is a test code to reproduce the issue :

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Builder;
using System.Threading.Tasks;
using Serilog.Filters;
using Serilog.Events;
using Serilog;
using System;

var webAppBuilder = CreateBuilderWithSerilog();
var webApp = webAppBuilder.Build();

try
{
    await webApp.StartAsync();
    webApp.Logger.LogInformation("Hello there !");
}
finally { await webApp.StopAsync(); }

webAppBuilder = CreateBuilderWithSerilog();
webAppBuilder.Services.AddHttpClient();
webApp = webAppBuilder.Build();
try
{
    await webApp.StartAsync();
    webApp.Logger.LogInformation("General kenobi ! (in an ugly way)");
}
finally { await webApp.StopAsync(); }

static WebApplicationBuilder CreateBuilderWithSerilog()
{
    var webAppBuilder = WebApplication.CreateBuilder();
    webAppBuilder.Host.UseSerilog((_, c) => c.MinimumLevel.Is(LogEventLevel.Information)
        .Filter.ByExcluding(Matching.FromSource("Microsoft.AspNetCore"))
        .Filter.ByExcluding(Matching.FromSource("Microsoft.Extensions"))
        .Filter.ByExcluding(Matching.FromSource("Microsoft.Hosting"))
        .Enrich.FromLogContext()
        .WriteTo.Console());

    return webAppBuilder;
}
Console.ReadLine();

And the output produced :

[09:14:02 INF] Hello there !
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\Users\User\source\repos\ConsoleApp1\bin\Debug\net5.0
info: ConsoleApp1[0]
      General kenobi ! (in an ugly way)
info: Microsoft.Hosting.Lifetime[0]
      Application is shutting down...

For precision, the issue does not happen with a classic hosted application.

What are the issues with asynchttpserver?

Hi

I noticed that the doc for asynchttpserver says;

This HTTP server has not been designed to be used in production, but for testing applications locally. Because of this, when deploying your application you should use a reverse proxy (for example nginx) instead of allowing users to connect directly to this server.

I was wondering what are the issues with asynchttpserver, that the nim maintainers consider it not fit for production?

Also, considering that prologue is built on top of this server, how is prologue planning to tackle these issues?

Draft - Minimal APIs (Feather + Houdini )Preview 4 Readiness

User experience/ expectation
Templates

In Preview 4

  • dotnet new minimal host
  • dotnet run
  • Auth works
  • List C# features : top level statements, maybe lambdas

New Features - Minimal Code for Minimal Apps
Faster with less ceremony

  • Minimal-Actions
  • Request delegate factory
  • Number of files has reduced
  • Benchmarks

Future

  • Swagger will be there in the future
  • C# Lambdas

Todo

  • Merge the code to dotnet repo

Unable to change the content root

This hack to make MVC, and RazorPages scanning work by default comes at a cost of not being able to change the content root. It's a pretty severe limitation for certain types of applications (I just hit this when trying to port one of my applications over).

Settings that affect IWebHostEnvironment and IHostEnvironment do not work

We expose an IWebHostEnvironment property on the builder (WebApplicationBuilder.Environment) in order to support conditional service registration (for e.g. base on the current environment). That property is currently incorrect when it comes to configuring the the host via UseEnvironment or UseContentRoot (or any other setting that affects the host configuration). We should decide how to fix it or what to do about this.

PS: We also added the IWebHostEnvironment to allow various part of the ASP.NET Core stack that scan for assets based on application name to work. e.g. MVC https://github.com/dotnet/aspnetcore/blob/2e4274cb67c049055e321c18cc9e64562da52dcf/src/Mvc/Mvc.Core/src/DependencyInjection/MvcCoreServiceCollectionExtensions.cs#L81-L88)

class Program
{
    static async Task Main(string[] args)
    {
        var builder = WebApplication.CreateBuilder(args);

        builder.Host.UseEnvironment("Staging");
        builder.Host.UseContentRoot(@"C:\dev\git\FeatherHttp\samples\");

        builder.Server.UseEnvironment("Testing");
        builder.Server.UseContentRoot(@"C:\dev\git\FeatherHttp\samples\");

        var env = builder.Environment.EnvironmentName; // null
        var contentRoot = builder.Environment.ContentRootPath; // cwd
    }
}

IWebHostEnvironment missing static assets from referenced projects

To try out featherhttp and see if it would work with Blazor WebAssembly, I created a new project using the Blazor Wasm template for 3.2 RC with an Asp.NET Core host. I just deleted the startup for the server host and changed Program.cs to following:

            builder.Services.AddControllersWithViews();
            builder.Services.AddRazorPages();
            var app = builder.Build();

            app.UseBlazorFrameworkFiles();
            app.UseStaticFiles();

            app.MapRazorPages();
            app.MapControllers();
            app.MapFallbackToFile("index.html");
           
            app.Run();

Running the program results in a 404. Stepping into app.UseBlazorFrameworkFiles shows that the webHostEnvironment has a NullFileProvider instead of the CompositeFileProvider (with the path to the static content for the referenced Blazor client project) that I would expect and which is correctly populated if you use the template as is.

Interestingly (or maybe not), calling GetServices returns two entires, one of which seems to have the correct WebRootFileProvider. This is not the environment, however, resolved inside app.UseBlazorFrameworkFiles.

Is this the expected behavior? I attempted to work through the source here, and for the standard WebHostBuilder to see what was happening, but couldn't quite pinpoint where they diverge. Is this possibly related to the changes for #19 and/or the use of the deferred host?

I can provide more information/clarification if needed.

Thanks!

Access to nuget package

Trying to install the package through dotnet add package FeatherHttp --prerelease is not working

Future plans

Hey @davidfowl
Do you have any future plans for this repo? Or is it just a showcase.
Tbh, it looks very interesting and cool to me, wanna help improve it if you have plans

API quirk: Accessing configuration during building services is awkward

Usually in ASP.NET Core, IConfiguration is available during ConfigureServices to allow configuring things like connection strings etc. It's currently impossible to do the same thing with feather e.g.:

WebApplication app = null;

builder.Services.AddSignalR().AddStackExchangeRedis(o =>
{
    // Read the redis service connection string
    var connection = app.Configuration["Redis:ConnectionString"];
    o.Configuration.EndPoints.Add(connection);
});

The above is getting a connection string from configuration and this only works because there happens to be a lambda that can also configure AddStackExchangeRedis. Now, most of the APIs in ASP.NET Core have a lambda version but it's really hard to use the version that takes a connection string directly:

var connectionString = ??;
builder.Services.AddSignalR().AddStackExchangeRedis(connectionString);

Since we haven't built configuration as yet it's not possible to get the connection string this early.

Rename this repo to featherhttp.framework

Calling it framework means that if you clone it, you end up with a repo called MyUserName/framework, which is incredibly non-descriptive :)

By all means just close this if you're not interested in having people fork it.

"CreateAppHost" task failed unexpectedly on app run

.NET Core SDK Version: 6.0.100-preview.3.21156.2

Steps

  • Installed the Featherhttp template
  • created a simple FeatherHttp hello world app
  • Run it - dotnet run
  • Got a build failed error :\Program Files\dotnet\sdk\6.0.100-preview.3.21156.2\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(522,5): error MSB4018: The "CreateAppHost" task failed unexpectedly.

image

[Question] Peculiarities of WriteJsonAsync<TValue>

Greetings @davidfowl !

Awhile back I needed help with something, and you helped answer my issue.

The way your library handles parsing for the HttpResponse object - is it superior to the suggested answer there?

In my case, I first parse the object to a json string (using JsonSerializer.Deserialize), and then I pass it to the HttpResponse object by its WriteAsync method, which utilizes the new System.IO.Pipelines API, followed by a HttpResponse.Body.FlushAsync call.

Looking forward to hearing from you!

gRPC support

Not sure of gRPC is already supported by this proj, if no please please please consider it :-) FeathergRPC FTW for nice fast bidirectional comms, then i can ditch golang.

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.