Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a new api function create_resource_with_regex #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

OmentaElvis
Copy link

This function will pass the uri as is to the Resource engine. No additional processing is done to check for query parameters and other path captures. The uri will be saved as a valid regex. It will also extract named captures from the regex and pass it to the Request parameters so that users can still use the original api of:

let server = TestServer::new().unwrap();
let resource = server.create_resource_with_regex("^/(?<group_id>.*)/(?<artifact_id>.*)/maven-metadata.xml$");
resource.status(Status::OK).body("{path.group_id}:{path.artifact_id}");

or

let server = TestServer::new().unwrap();
let resource = server.create_resource_with_regex("^/(?<group_id>.*)/(?<artifact_id>.*)/maven-metadata.xml$");
resource.method(Method::GET).status(Status::OK)
            .body_fn(|param| {
                let group_id = param.path.get("group_id").unwrap();
                let artifact_id = param.path.get("artifact_id").unwrap();

                format!("{group_id}:{artifact_id}")
            });

This will allow for fine grained control of uri therefore allowing extraction of uri segments for further processing of body response.

Did not affect the existing api.

- This will treat the uri string as valid regex
without doing any pre-processing to remove
query parameters.
- The original API is also preserved for non complex
regex operations.

Signed-off-by OmentaElvis <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant