motiv-labs / janus

An API Gateway written in Go
https://hellofresh.gitbooks.io/janus
MIT License
2.79k stars 317 forks source link

Support url parameters #262

Closed stefanoj3 closed 6 years ago

stefanoj3 commented 6 years ago

What does this PR do?

Adds supports for named parameters in the target url.

Example Given this configuration

Definition{
    ListenPath: "/api/recipes/{id:[\\da-f]{24}}",
    Upstreams: &Upstreams{
        Balancing: "roundrobin",
        Targets:   []*Target{{Target: "http://localhost:9089/recipes/{id}"}},
    },
    Methods:    []string{"ALL"},
    StripPath:  false,
    AppendPath: false,
}

If I call /api/recipes/5252b1b5301bbf46038b473f my call should be forwarded to http://localhost:9089/recipes/5252b1b5301bbf46038b473f

olvlvl commented 6 years ago

WANT! https://github.com/hellofresh/janus/issues/260

codecov[bot] commented 6 years ago

Codecov Report

Merging #262 into master will decrease coverage by 0.17%. The diff coverage is 28.57%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #262      +/-   ##
==========================================
- Coverage   45.21%   45.04%   -0.18%     
==========================================
  Files          66       67       +1     
  Lines        2433     2460      +27     
==========================================
+ Hits         1100     1108       +8     
- Misses       1279     1298      +19     
  Partials       54       54
Impacted Files Coverage Δ
pkg/proxy/register.go 0% <0%> (ø) :arrow_up:
pkg/router/listen_path_parameter_name_extractor.go 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 73684a7...a4cd8f0. Read the comment docs.

stefanoj3 commented 6 years ago

@rafaeljesus updated with the changes you requested

stefanoj3 commented 6 years ago

Updated with the requested changes and with the help of @rafaeljesus I added also an automation test

rafaeljesus commented 6 years ago

@stefanoj3 we could add this new feature on the docs as well https://github.com/hellofresh/janus/docs/proxy/routing_capabilities.md a simple example is enough

stefanoj3 commented 6 years ago

Doc updated

rafaeljesus commented 6 years ago

@stefanoj3 @olvlvl really appreciate your effort to push this feature, thank you

olvlvl commented 6 years ago

Thanks guys! I'm really glad about this feature!