How to pass folder paths in Angular 6 Get API Method?
In my angular application, I have to pass an Id and a folder path as a parameter in Angular 6.
Please see the below code snippet
in typescript
let subDirectory: string = "folder1/folder2/folder3";
let id: number = 6 ;
this.http.get<ItemDetails>(this.appService.baseUrl + 'api/File/' + id + "/" + subDirectory)
Here the problem is: the API call becomes
this.http.get(this.appService.baseUrl + 'api/File/' + id + "/" + "folder1/folder2/folder3")
if we have only "folder1" as subdirectory then no issues.
"/folder2/folder3" makes the issue
in Controller
[HttpGet("{id:int}/{subDirectotry?}")]
[ResponseCache(NoStore = true)]
public async Task<IActionResult> Get(int id, string subDirectotry)
{
}
Please, anyone, help me to achieve the same.
angular typescript asp.net-core
add a comment |
In my angular application, I have to pass an Id and a folder path as a parameter in Angular 6.
Please see the below code snippet
in typescript
let subDirectory: string = "folder1/folder2/folder3";
let id: number = 6 ;
this.http.get<ItemDetails>(this.appService.baseUrl + 'api/File/' + id + "/" + subDirectory)
Here the problem is: the API call becomes
this.http.get(this.appService.baseUrl + 'api/File/' + id + "/" + "folder1/folder2/folder3")
if we have only "folder1" as subdirectory then no issues.
"/folder2/folder3" makes the issue
in Controller
[HttpGet("{id:int}/{subDirectotry?}")]
[ResponseCache(NoStore = true)]
public async Task<IActionResult> Get(int id, string subDirectotry)
{
}
Please, anyone, help me to achieve the same.
angular typescript asp.net-core
1
And what is the problem?
– Antoniossss
2 days ago
updated question
– Krishnan
2 days ago
Typescript part is irrelevant here. paste full url you are trying to access and gives you 404
– Antoniossss
2 days ago
add a comment |
In my angular application, I have to pass an Id and a folder path as a parameter in Angular 6.
Please see the below code snippet
in typescript
let subDirectory: string = "folder1/folder2/folder3";
let id: number = 6 ;
this.http.get<ItemDetails>(this.appService.baseUrl + 'api/File/' + id + "/" + subDirectory)
Here the problem is: the API call becomes
this.http.get(this.appService.baseUrl + 'api/File/' + id + "/" + "folder1/folder2/folder3")
if we have only "folder1" as subdirectory then no issues.
"/folder2/folder3" makes the issue
in Controller
[HttpGet("{id:int}/{subDirectotry?}")]
[ResponseCache(NoStore = true)]
public async Task<IActionResult> Get(int id, string subDirectotry)
{
}
Please, anyone, help me to achieve the same.
angular typescript asp.net-core
In my angular application, I have to pass an Id and a folder path as a parameter in Angular 6.
Please see the below code snippet
in typescript
let subDirectory: string = "folder1/folder2/folder3";
let id: number = 6 ;
this.http.get<ItemDetails>(this.appService.baseUrl + 'api/File/' + id + "/" + subDirectory)
Here the problem is: the API call becomes
this.http.get(this.appService.baseUrl + 'api/File/' + id + "/" + "folder1/folder2/folder3")
if we have only "folder1" as subdirectory then no issues.
"/folder2/folder3" makes the issue
in Controller
[HttpGet("{id:int}/{subDirectotry?}")]
[ResponseCache(NoStore = true)]
public async Task<IActionResult> Get(int id, string subDirectotry)
{
}
Please, anyone, help me to achieve the same.
angular typescript asp.net-core
angular typescript asp.net-core
edited 2 days ago
asked 2 days ago
Krishnan
507621
507621
1
And what is the problem?
– Antoniossss
2 days ago
updated question
– Krishnan
2 days ago
Typescript part is irrelevant here. paste full url you are trying to access and gives you 404
– Antoniossss
2 days ago
add a comment |
1
And what is the problem?
– Antoniossss
2 days ago
updated question
– Krishnan
2 days ago
Typescript part is irrelevant here. paste full url you are trying to access and gives you 404
– Antoniossss
2 days ago
1
1
And what is the problem?
– Antoniossss
2 days ago
And what is the problem?
– Antoniossss
2 days ago
updated question
– Krishnan
2 days ago
updated question
– Krishnan
2 days ago
Typescript part is irrelevant here. paste full url you are trying to access and gives you 404
– Antoniossss
2 days ago
Typescript part is irrelevant here. paste full url you are trying to access and gives you 404
– Antoniossss
2 days ago
add a comment |
3 Answers
3
active
oldest
votes
in simple words, define a function to call api in your service
getItemsDetails (id: number, subDirectory: string) {
return this.http.get<ItemDetails>(`${this.appService.baseUrl}api/File/${id}/${ subDirectory}`);
}
to call in componnet;
let subDirectory: string = "folder1/folder2/folder3";
let id: number = 6 ;
this.serviceName.getItemsDetails(id, subDirectory).subscribe(() => {
// -> do what ever you want do with response.
})
add a comment |
Most probably you're getting 404 errors , try to encode the subDirectory using encodeURIComponent , then try to unescape once you receive the request.
add a comment |
You could try catch-all route parameters with {*} like below:
[HttpGet("{id:int}/{*subDirectotry}")]
[ResponseCache(NoStore = true)]
public async Task<IActionResult> Get(int id, string subDirectotry)
{
return Ok();
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53945492%2fhow-to-pass-folder-paths-in-angular-6-get-api-method%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
in simple words, define a function to call api in your service
getItemsDetails (id: number, subDirectory: string) {
return this.http.get<ItemDetails>(`${this.appService.baseUrl}api/File/${id}/${ subDirectory}`);
}
to call in componnet;
let subDirectory: string = "folder1/folder2/folder3";
let id: number = 6 ;
this.serviceName.getItemsDetails(id, subDirectory).subscribe(() => {
// -> do what ever you want do with response.
})
add a comment |
in simple words, define a function to call api in your service
getItemsDetails (id: number, subDirectory: string) {
return this.http.get<ItemDetails>(`${this.appService.baseUrl}api/File/${id}/${ subDirectory}`);
}
to call in componnet;
let subDirectory: string = "folder1/folder2/folder3";
let id: number = 6 ;
this.serviceName.getItemsDetails(id, subDirectory).subscribe(() => {
// -> do what ever you want do with response.
})
add a comment |
in simple words, define a function to call api in your service
getItemsDetails (id: number, subDirectory: string) {
return this.http.get<ItemDetails>(`${this.appService.baseUrl}api/File/${id}/${ subDirectory}`);
}
to call in componnet;
let subDirectory: string = "folder1/folder2/folder3";
let id: number = 6 ;
this.serviceName.getItemsDetails(id, subDirectory).subscribe(() => {
// -> do what ever you want do with response.
})
in simple words, define a function to call api in your service
getItemsDetails (id: number, subDirectory: string) {
return this.http.get<ItemDetails>(`${this.appService.baseUrl}api/File/${id}/${ subDirectory}`);
}
to call in componnet;
let subDirectory: string = "folder1/folder2/folder3";
let id: number = 6 ;
this.serviceName.getItemsDetails(id, subDirectory).subscribe(() => {
// -> do what ever you want do with response.
})
answered 2 days ago
rijin
934514
934514
add a comment |
add a comment |
Most probably you're getting 404 errors , try to encode the subDirectory using encodeURIComponent , then try to unescape once you receive the request.
add a comment |
Most probably you're getting 404 errors , try to encode the subDirectory using encodeURIComponent , then try to unescape once you receive the request.
add a comment |
Most probably you're getting 404 errors , try to encode the subDirectory using encodeURIComponent , then try to unescape once you receive the request.
Most probably you're getting 404 errors , try to encode the subDirectory using encodeURIComponent , then try to unescape once you receive the request.
answered 2 days ago
Haidar Zeineddine
8325
8325
add a comment |
add a comment |
You could try catch-all route parameters with {*} like below:
[HttpGet("{id:int}/{*subDirectotry}")]
[ResponseCache(NoStore = true)]
public async Task<IActionResult> Get(int id, string subDirectotry)
{
return Ok();
}
add a comment |
You could try catch-all route parameters with {*} like below:
[HttpGet("{id:int}/{*subDirectotry}")]
[ResponseCache(NoStore = true)]
public async Task<IActionResult> Get(int id, string subDirectotry)
{
return Ok();
}
add a comment |
You could try catch-all route parameters with {*} like below:
[HttpGet("{id:int}/{*subDirectotry}")]
[ResponseCache(NoStore = true)]
public async Task<IActionResult> Get(int id, string subDirectotry)
{
return Ok();
}
You could try catch-all route parameters with {*} like below:
[HttpGet("{id:int}/{*subDirectotry}")]
[ResponseCache(NoStore = true)]
public async Task<IActionResult> Get(int id, string subDirectotry)
{
return Ok();
}
answered 2 days ago
Tao Zhou
4,87031128
4,87031128
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53945492%2fhow-to-pass-folder-paths-in-angular-6-get-api-method%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
And what is the problem?
– Antoniossss
2 days ago
updated question
– Krishnan
2 days ago
Typescript part is irrelevant here. paste full url you are trying to access and gives you 404
– Antoniossss
2 days ago