scottoffen / grapevine Goto Github PK
View Code? Open in Web Editor NEWFast, unopinionated, embeddable, minimalist web framework for .NET
Home Page: https://scottoffen.github.io/grapevine/
License: MIT License
Fast, unopinionated, embeddable, minimalist web framework for .NET
Home Page: https://scottoffen.github.io/grapevine/
License: MIT License
I downloaded the source and Import Grapeseed and Grapevine into my solution that contain my own Windows Form Project.
I wrote this codes:
private void Main_Load(object sender, EventArgs e)
{
LoadApiServer();
}
private void LoadApiServer()
{
using (var server = RestServerBuilder.UseDefaults().Build())
{
server.Start();
MyLogBox.WriteLine("API Server Started.");
}
}
This is MyResource Class:
namespace MyWinFormApplication
{
[RestResource]
public class MyResource
{
[RestRoute("Get", "/api/info")]
public async Task Test(IHttpContext context)
{
await context.Response.SendResponseAsync("Info Api Called");
}
}
}
After run the Winform Application, server not starts and not listening on default port (localhost:1234) and I can't use it.
Is it possible to use Grapevine in Windows Form apps?
Is there a way to correctly parse Form Data? I have a form that accepts one file and I'm unable to parse and save the file effectively although I can do it easily on an ASP.NET API
For more context, I saw this response and tried to do the same without success. Must be because it's old.
scottoffen/grapevine-legacy#193
Feature request: Swap usage of HttpListeners for other libraries.
Quickly realized upon trying to use this library that you are heavily dependent on MS HttpListener functionality for routing as well as your current iteration of "builder" i.e. factory classes.
In particular there is no way to use embedded certs (for a use case for embedded certs where installing certs is counterproductive and undesirable). This is entirely possible and multiple other C# libraries do this without a problem. However the use of HttpListener makes this difficult if not impossible to achieve with this library. As a result I am evaluating different more capable libraries...
Hi! I started playing with Grapevine recently, but still couldn't figure out how to properly respond with UTF-8 characters.
For example, "Injeção" becomes "Injeção".
Among other things, I tried setting Response.ContentEncoding to Text.Encoding.UTF8, but nothing seemed to work.
What am I doing wrong?
I can start the server and even get the correct response (using Mozilla Firefox), but right after receiving it, the server just crashes.
I'm not exactly sure what I'm doing wrong and Google hasn't helped, sorry.
trce: Grapevine.IRouteScanner[0]
Begin Global Route Scanning
trce: Grapevine.IRouteScanner[0]
Generated route Grapevine.Route`1[MainServer.MyResource]
trce: Grapevine.IRouteScanner[0]
Scan of method Test complete: 1 total routes found
trce: Grapevine.IRouteScanner[0]
Scan of type MyResource complete: 1 total routes found
trce: Grapevine.IRouteScanner[0]
Global Route Scanning Complete: 1 total routes found
trce: Grapevine.IRestServer[0]
c29054bd-64b1-4891-8350-ade2a69cca22 : Request Received Get /api/test
trce: Grapevine.IRestServer[0]
c29054bd-64b1-4891-8350-ade2a69cca22 : Invoking OnRequest Handlers for Get /api/test
trce: Grapevine.IRestServer[0]
c29054bd-64b1-4891-8350-ade2a69cca22 : OnRequest Handlers Invoked for Get /api/test
trce: Grapevine.IRestServer[0]
c29054bd-64b1-4891-8350-ade2a69cca22 : Routing request Get /api/test
dbug: Grapevine.IRouter[0]
c29054bd-64b1-4891-8350-ade2a69cca22 : Routing Get /api/test
dbug: Grapevine.IRouter[0]
c29054bd-64b1-4891-8350-ade2a69cca22 : Matching routes discovered for Get /api/test
trce: Grapevine.IRouter[0]
c29054bd-64b1-4891-8350-ade2a69cca22 : Invoking before routing handlers for Get /api/test
trce: Grapevine.IRouter[0]
c29054bd-64b1-4891-8350-ade2a69cca22 : Before routing handlers invoked for Get /api/test
dbug: Grapevine.IRouter[0]
c29054bd-64b1-4891-8350-ade2a69cca22 : Executing MyResource.Test for Get /api/test
dbug: Grapevine.IRouter[0]
c29054bd-64b1-4891-8350-ade2a69cca22 : 1 of 1 routes invoked
trce: Grapevine.IRouter[0]
c29054bd-64b1-4891-8350-ade2a69cca22 : Invoking after routing handlers for Get /api/test
trce: Grapevine.IRouter[0]
c29054bd-64b1-4891-8350-ade2a69cca22 : After routing handlers invoked for Get /api/test
trce: Grapevine.IRestServer[0]
514cd167-113e-44ee-b52f-9fd95b1c3bb5 : Request Received Get /favicon.ico
trce: Grapevine.IRestServer[0]
514cd167-113e-44ee-b52f-9fd95b1c3bb5 : Invoking OnRequest Handlers for Get /favicon.ico
trce: Grapevine.IRestServer[0]
514cd167-113e-44ee-b52f-9fd95b1c3bb5 : OnRequest Handlers Invoked for Get /favicon.ico
trce: Grapevine.IRestServer[0]
514cd167-113e-44ee-b52f-9fd95b1c3bb5 : Routing request Get /favicon.ico
dbug: Grapevine.IRouter[0]
514cd167-113e-44ee-b52f-9fd95b1c3bb5 : Routing Get /favicon.icoProcess is terminated due to StackOverflowException.
An unhandled exception of type 'System.StackOverflowException' occurred in Grapevine.dll
This happens with the sample project if you provide a route not defined. http://localhost:1234/asdfg
for example.
This will also happen with the sample code shown in the project readme if the request is made in the browser. This is because the browser requests for the favicon.ico
to which there is no route for that defined.
Self explanatory.
It's still 2021, 1/26
I have built a server in the past that works on localhost, but today after pasting a sample code of it i could get it work on in new project.
here is my code:
ServerSettings setting;
RestServer server;
public Core()
{
setting = new ServerSettings();
setting.Port = "50055";
setting.Host = "*";
Start();
}
private void Start()
{
using (server = new RestServer(setting))
{
server.LogToConsole(Grapevine.Interfaces.Shared.LogLevel.Debug);
server.Start();
}
}
this code works on my previous app(localhost) but not with new app. i have no idea.
IHttpContext context.Request.Payload was available in 4.2 version.
But it seems to have been removed.
How do I go about getting the request payload?
I tried this code below. Sometimes it works. Sometimes it doesn't return any data (even when the content-length is greater than 0.
using var reader = new StreamReader(context.Request.InputStream, context.Request.ContentEncoding);
var payload = await reader.ReadToEndAsync();
Hey, is it possible to add custom middleware? In my example, I need to parse the request body as JSON, so I don't wanna do it every time in each route, would be great if it can be included as a middleware and an extra string field where it contains a JSON that can be parsed from there, or even a generic parameter specifier that can be passed via attributes or something, so that the body is read as the specified type directly.
Thanks!
Hello Scott,
using your great grapevine / grapeseed assemblies from a COM exe via COM-Interop, referenced assemblies need to have a strong name.
Could you please provide signed assemblies, e.g. using sn tool to create your own sn-file.
Hint: in your AssemblyInfo.cs I had to insert the public key from sn-file.
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute("Grapevine.Tests,PublicKey=xxx")]
You can easily extract the public key "xxx", refer to: https://stackoverflow.com/questions/1123683/how-to-declare-a-friend-assembly
Thank you very much in advance!
Michael.
Trying to setup something simple for external logging purposes using rest endpoints on a server built in .NET.
Are there any examples of a more complete setup using Grapevine? Something that goes beyound localhost testing?
Like being able to set the host IP and port? I'm not sure where this is done.
server.Prefixes.Add("http://*:50055");
That line of code throws an exception for me.
'Only Uri prefixes ending in '/' are allowed. (Parameter 'uriPrefix')'
Running 5.0.0-rc
Hi,
I'm discovering this project and plan to use it.
But I'm developing in a context where I can't migrate to new framework Core.
For that, I will go to version 4 but I don't find any documentation or sample or Wiki page for version 4.
Where can I get it?
Thanks
Do we have WebSocket support in Grapevine 5? Or server sent events? If no, are they planned?
Hello. I've found Grapevine V4. It looks great. Some feedback from one person.. I won't use Grapevine V5 because of the dependencies:
Grapeseed >= 5.0.0-rc.10)
Microsoft.Extensions.DependencyInjection >= 5.0.1
Microsoft.Extensions.DependencyInjection.Abstractions >= 5.0.0
Microsoft.Extensions.Logging.Abstractions >= 5.0.0
Microsoft.Extensions.Logging.Console >= 5.0.0
I don't want a nuget package which pulls in 5 others, then potentially more transitive dependencies. No thanks. Please just give me a nuget package with no dependencies like V4.
RestResources in older versions seem to inherit the RestServer from a base class.
In the latest build, this feature seems to have disappeared, and RestResource is an attribute.
I run multiple instances of RestServer and need the RestResources to behave a little different for each RestServer instance.
Any hints on how to pass RestServer into RestResources?
Seems a little too complex for me to figure out.
Hi,
I use grapevine to make a rest server.
When logging into windows with local admin rights, everything works normally.
But when logging into windows with the domain and user rights, the rest server cannot start.
I followed this instruction https://scottoffen.github.io/grapevine-legacy/en/using-httplistener.html
to successfully execute the command:
netsh http add urlacl url=http://+:1234/ user=abc.com.vn\thangnv
Please help me resolve this issue
Hi all
The app that I am developing, is using 50% of my CPU (virtual machine) and the version that I use is V 5.0.0 rc.7 and I reduced the version to rc.6, then the cpu usage becomes 0% :)
So there is an issue in the latest pre-release (rc.7). Could you please check the problem?
I see that, a similar problem happened here
scottoffen/grapevine-legacy#138
Anyway I am using rc.6 for now and there is no problem in my side. Just want to mention that the rc.7 uses high cpu resource!
thanks
Need to updated how middleware is handled so that it doesn't break when serving static content
Hello and thanks for this wonderful project @scottoffen !
I started implementing in my project grapevine 4 since 5 was in rc. It was working quite fine but all my methods are async to I decided to move and try grapevine5.
I reimplemented routes as specified in the docs, added * as listening host through prefixes and all (I hope you can finish documentation because it is VERY scarce :-( ) but with grapevine5-rc7 as soon as I hit a route (for example a get route) the c# program containing the server immediately crashes with memory access violation.
has exited with code -1073741819 (0xc0000005) 'Access violation'.
Am I missing something? Thanks in advance!
EDIT: For what I can see the access violation crash is completely random, it happens on like 3/5 starts of the server both on get and post routes. Sometimes it is completely fine and works!
EDIT2: I found out rc6 is completely stable, so the problem must reside in some changes made in between, hope that can help ;)
In 4.0 I could write to the output stream in chunks, and then close the stream and the response. But I guess now, Grapevine checks and tries to close the response without checking if it's already closed resulting in an exception at the end of the response (after all the data has already been sent)
In theory just checking if the response has closed first would be sufficient, but a more sensible system would be to have a "MarkComplete"-like method so we can manually handle the outputstream and then let Grapevine know that the response is finished.
When starting the server in the console the text output has too much slashes
" Stop server by going to http://localhost:1234//api/stop"
should be
" Stop server by going to http://localhost:1234/api/stop"
In Grapevine V4, i can do that:
[RestRoute(PathInfo = @"/")]
public IHttpContext ROOT(IHttpContext context)
{
context.Response.SendResponse(Encoding.UTF8.GetBytes("Welcome to Grapevine"));
return context;
}
Add the following extension methods to IHttpResponse
for sending responses with the status code as the first parameter:
IHttpResponse.SendResponseAsync(HttpStatusCode statusCode, byte[] content)
IHttpResponse.SendResponseAsync(HttpStatusCode statusCode, string content)
IHttpResponse.SendResponseAsync(HttpStatusCode statusCode, Stream content)
In response to #87
We have used Grapevine v4 for awhile and recently found an issue whereby our applications don't support HTTPS connections when they are run as .NET core apps in Linux containers. We have attributed this to dotnet/runtime#32721 (ignore the title of the post).
Can anyone tell me whether this is resolved in v5? And if so, how is Grapevine told which certificate to use (netsh.exe not available on a Linux container host)?
Thanks in anticipation!
I'm trying to serve up a html site using javascript modules, but it won't run the javascript. How do a serve them with a
Content-Type
header text/javascript
??
Thanks
The documentation leaves this really unclear
Say I have a route like this
[RestRoute("Get", "/updatetasks/{blockID}/{isChecked}")]
What's the proper way to hit this route?? The below did not work.
localhost/updatetasks/myblockid/false
I've tried so many variations and none work. Using ?blockID params don't work either...
Please advise.
Found in 5.0.0-rc.7
The sample project route http://localhost:1234/api/stop fails to stop the running server because the instance is being pulled from a different service provider than the one used to generate the running server (ergo, different instance).
The following fix will be in the RestServerBuilder.Build()
method of the next version:
// Override with instances
Services.AddSingleton<IRestServer>(server);
Services.AddSingleton<IRouter>(server.Router);
Services.AddSingleton<IRouteScanner>(server.RouteScanner);
This will override the previous service registration of the interface to a concretion with a registration to an instance.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.