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

Add support for query parameter name overwrite with the user given name using @http:Query annotation in http service #7006

Closed
lnash94 opened this issue Sep 18, 2024 · 0 comments · Fixed by ballerina-platform/module-ballerina-http#2152

Comments

@lnash94
Copy link
Member

lnash94 commented Sep 18, 2024

Description:
In general query parameters can have the names full-name, first-name which are not align with the ballerina naming conventions.
Describe your problem(s)
when using these query parameters, users may face code readability issues ex: "full-name". The escaped characters can make the code harder to read and understand, leading to confusion and potential mistakes during development. but since these are wired with a path, we cannot overwrite it with the name. we introduced query annotation via this issue

Describe your solution(s)

Introducing a new annotating field @http:Query parameters with metadata. The field will be specified using a syntax similar to the following:

public type HttpQuery record {|
   string name?;
|}

HTTP service with resource function

import ballerina/http;

service /v1 on new http:Listener(9090) {

    # Annotation using the query parameter name
    resource isolated function get customer/groups(@http:Query { name: "customer-group"} customerGroup ) returns Person|error {
        //logic here    ...
    }
}

# Annotation using in-record field
type Person record {
   @http:Field {| name: "first-name"|}
   string firstName;
   int age;
}

Related Issues (optional):
Partial support for #6867

Suggested Labels (optional):

Suggested Assignees (optional):

@lnash94 lnash94 self-assigned this Sep 18, 2024
@lnash94 lnash94 changed the title Add support for query parameter name overwrite with the user given name using @http:Query annotation in http client Add support for query parameter name overwrite with the user given name using @http:Query annotation in http service Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant