Comments (18)
Hi,
I've the same need. I use the ninja patch below to support one wildcard in the middle of the url.
--- Unosquare.Labs.EmbedIO/Modules/WebApiModule.cs
+++ Unosquare.Labs.EmbedIO/Modules/WebApiModule.cs
@@ -32,11 +32,17 @@
var path = context.RequestPath();
var verb = context.RequestVerb();
var wildcardPaths = DelegateMap.Keys
- .Where(k => k.EndsWith("/" + ModuleMap.AnyPath))
+ .Where(k => k.Contains("/" + ModuleMap.AnyPath))
.Select(s => s.ToLowerInvariant())
.ToArray();
- var wildcardMatch = wildcardPaths.FirstOrDefault(p => path.StartsWith(p.Substring(0, p.Length - 1)));
+ var wildcardMatch = wildcardPaths.FirstOrDefault(
+ p => // wildcard at the end
+ path.StartsWith(p.Substring(0, p.Length - ModuleMap.AnyPath.Length))
+ // wildcard in the middle so check both start/end
+ || (path.StartsWith(p.Substring(0, p.IndexOf(ModuleMap.AnyPath)))
+ && path.EndsWith(p.Substring(p.IndexOf(ModuleMap.AnyPath)+1)))
+ );
if (string.IsNullOrWhiteSpace(wildcardMatch) == false)
path = wildcardMatch;
A better solution could be to support regexp and map match group to argument of the method.
example :
[WebApiHandler(HttpVerbs.Get, RelativePath + "people/{id:([0-9]+)}")]
public bool GetPeople(WebServer server, HttpListenerContext context, int id) {
...
}
from embedio.
Can you post a sample where do you need the support to middle wilcard?
Thank you
On Thu, Mar 24, 2016 at 8:43 AM, Jon Ford [email protected] wrote:
Correct me if I'm mistaken, but it seems like the "*" wildcard is only
supported at the end of a URL rather than anywhere within it. Is this
intentional? Looking through the documentation, I don't see any examples of
a wildcard not at the end of a URL. Some of my endpoints require a wildcard
in the middle of a URL, and I'm sure other developers have the same
requirements.β
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#28
Geo PΓ©rez
from embedio.
Sure. In my API, I have the concept of groups of devices. So, to get the nth group of devices, the endpoint that makes the most sense to me is /api/groups/n/devices.
Alternatives:
/api/groups/n
Doesn't make sense since groups have more properties than just devices.
/api/groups/devices/n
This is what I'm currently using as a workaround, but I'm not satisfied. Here's why: I also need an API endpoint the get the groups that are assigned to a device. If wildcard is supported in the middle of a URL, then my ideal endpoint is /api/devices/n/groups. Otherwise, I must use /api/devices/groups/n. Now an API user might be confused about which endpoint does what (/api/devices/groups/n vs. /api/groups/devices/n). When the wildcard is in the middle of the endpoint, the endpoint reads more like a language and we can deduce what it does. When the wildcard comes at the end of the endpoint, it is harder to tell whether the identifier applies to the first resource or the second (group or device).
I also have endpoints that require multiple wildcards, but that is a separate issue :)
from embedio.
Up-voted. I agree with Jon.
from embedio.
@bufferUnderrun would you be able to help us support regex-based routing without breaking wildcard routing by providing a pull request?
from embedio.
I commited the @bufferUnderrun suggestion with an Unit Test and it's seems to be fine. But I agreed to include better support with regex to routes and bind segments as arguments in the WebApi handler.
from embedio.
@geoperez the routing attribute needs to have the default constructor to use wildcard matching and add an additional constructor taking in a string and a RoutingStrategy enum that has the members Wildcard and RegEx
from embedio.
@mariodivece a very early version to support Regex and send args directly to the WebApi method is available in the next test file: https://github.com/unosquare/embedio/blob/master/Unosquare.Labs.EmbedIO.Tests/TestObjects/TestRegexController.cs
Let me know your thoughts
from embedio.
cool, i'll test this.
from embedio.
In your last commit, you use the new syntax introduced in C# 6.0 for property initializer.
Do you plan to retargeting to the most recent C# version ? because vs2013 does not support this...
edit : it seems for vs2013 you have to install the nuget package "Microsoft.Net.Compilers".
from embedio.
we are now using VS 2015/C# 6. The solution file and some areas of the codes are now starting to use the features provided by C# 6. We will however continue to target .net framework 4.5 as there is no apparent benefit for this project to target later versions.
from embedio.
@geoperez The implementation is incomplete. Please avoid publishing a nuget package until the async implementation is completed. Starting to look pretty good though! π
from embedio.
@mariodivece hum, so after install vs2008 to maintain a old asp.net mvc1 project, vs2010 for a outlook addin and vs2013 for my current aspnet mvc5 projects, i will install vs2015... :) Hope embedio will rule them all π
from embedio.
@bufferUnderrun Ha! Story of my life. @geoperez has it worse: He has to run VB6 on a VM to support some really old application.
from embedio.
πΏ
from embedio.
@geoperez you win !
from embedio.
@mariodivece async methods are available with Regex Strategic. I created more unit tests to check async implementation in both ways.
from embedio.
The new Nuget was published.
from embedio.
Related Issues (20)
- How to send statuscode 202 HOT 1
- EmbedIO 3.5.0 NuGet package references wrong/old version of Unosquare.Swan.Lite HOT 22
- System.ObjectDisposedException when processing multiple requests at once HOT 2
- WithZipFile should open a read only handle(or have the option to) HOT 2
- FileModule or StaticFolderModule get stuck returning medium files HOT 4
- Add XML as response type
- EmbedIO Dual-Stack Localhost Listener Causes Empty Replies HOT 1
- How can I custom the Server header HOT 2
- Disable request logging only
- Cookies issue
- EmbedIO.Samples console app does not work when PublishAot is set to true HOT 2
- Web Server does not work in Xamarin.iOS (IOS-17) HOT 3
- How to report progess via api - event-stream
- HttpContext.OnClose not firing HOT 1
- Getting rid of double quotes around strings in a Web API response (turning off JSON serialization) HOT 1
- Issue Serving Static Folder Xamarin ( 3.5.2) Forms on Android
- Request.Url mixing up http and https
- server stop responding after some time HOT 4
- The return array is empty. HOT 1
- Crash the webserver and restart the main application
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from embedio.