0

I've a Util.ts which will have all the API endpoints.

In my component will import the Api class and make use of the API's.

Now, One of the API endpoint is having dynamic values, that I need to append to the URL.

Utils.ts

export class Api {
    public static PROGRESS_ISSUE = 'https://xxx/rest/api/2/search?jql=project%20%3D%2025764%20AND%20status%20%3D%20%22In%20Progress%22&fields=id,key,status,project&maxResults=100'
}

In the above, I wanted to make the project & status as dynamic values which I'll be passing in the service.

Service.ts

import { Api } from './api/utils'; 

  getJiraOpenIssues(id: number, status:string) {
    return this.http.get<any>( Api.PROGRESS_ISSUE )
    .subscribe(count => console.log(count.total));
  }
1

2 Answers 2

1

You could place some placeholder string on the PROGRESS_ISSUE, and then use replace to replace it with the actual value:

export class Api {
  public static PROGRESS_ISSUE = "https://xxx/rest/api/2/search?jql=project=PROJECTPLACEHOLDER&status=STATUSPLACEHOLDER&fields=id,key,status,project&maxResults=100"
}

Then, in your getJiraOpenIssues method, use replace:

import { Api } from './api/utils';

getJiraOpenIssues(id: number, status: string) {
  const apiUrl = Api.PROGRESS_ISSUE
    .replace('PROJECTPLACEHOLDER', 'YOUR PROJECT ID HERE')
    .replace('STATUSPLACEHOLDER', 'YOUR PROJECT STATUS HERE');
  return this.http.get<any>(apiUrl)
    .subscribe(count => console.log(count.total));
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can simply append values like we concat string with + operator.

   getJiraOpenIssues(id: number, status:string) {
        return this.http.get(Api.PROGRESS_ISSUE + '' + id + '/'+status)
            .map((response) => response.json());
    }

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.