How can I store the data retrieved from an API and then forward it to a URL using Angular?

Is there a way to save and pass the data received from an API to a URL in Angular?

SERVICE.ts

readonly apiUrl = 'http://localhost:49940/';

constructor(private http: HttpClient) { }

getUserName(): Observable<any> {
  return  this.http.get<any>(this.apiUrl+'api/Account/GetUserClaims');
}

get(userName: string): Observable<any> {
  let newURL = `https://...?codSog=${userName}`;
  return this.http.get<any>(newURL);
}

Answer №1

Retrieve the information from the API:

fetchData(item: T): Observable<T> {
  return this.http.get<T>('apiUrl');
}

Store it :

store(){
  this.fetchData().subscribe(res => this.savedItem = res,
    err => console.log(err),
    _ => console.log('item saved'));
}

Forward it to the following URL:

forwardData(item: T): Observable<T> {
  return this.http.post<T>('destinationUrl', item):
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The property X within the ClassB type cannot be assigned to the identical property within the parent type ClassA

I deal with the following set of Typescript classes: Firstly, we have an abstract class export abstract class MyAbstractClass { ... } Next is Class A which implements the methods from the abstract class export ClassA extends MyAbstractClass { ...

Issue encountered while deploying Firebase Functions: Unable to parse function triggers

Experiencing difficulty deploying firebase functions from an angular project after updating to the latest firebase-tools 7.8.1 version. The project's package.json contains "firebase-admin": "~6.0.0", "firebase-functions": "^2.1.0", and "firebase-funct ...

Oh no! A catastrophic NG_BUILD error has occurred: The mark-compacts are not working effectively due to an allocation failure near the heap limit. The JavaScript

While working on my Angular application, I keep encountering a JavaScript out of memory issue as indicated below: @bb-cli/bb-ang] ERR! NG_BUILD FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory I&apo ...

Attempting to integrate WebdriverIO into an Angular Electron application

Context: Currently, I am in the process of implementing the fundamental WebdriverIO example within an Angular Electron App. My application is built on the foundation of the Angular Electron Boilerplate. To set up, I have installed webdriverio and @types/we ...

Is Typescript capable of converting ES6 code to ES5 during transpilation?

Currently, I'm in the process of developing an application utilizing Angular 2 and TypeScript. My goal is to incorporate a JavaScript method, specifically 'filter' for arrays, that is compatible with IE 11+, Chrome 45+, and other similar bro ...

Using mat-select along with formControl to establish the default value

I'm struggling to assign a default value to my formControl, but it doesn't seem to be working as expected. select-hint-error-example.ts export class SelectHintErrorExample { animalControl = new FormControl('', [Validators.required]) ...

How to leverage async/await within loops in Node.js for optimized performance and efficiency

Hey there, I'm working on my nodejs api where I need to fetch data inside a loop and then perform another loop to save data in a different table. Can anyone guide me on how to achieve this? Below is a snippet of what I have attempted so far without su ...

How to effectively send an HTTP GET request to a REST API in Angular 2 and save the response in a JSON object

Currently, I am attempting to execute a GET request to the GitHub API using Angular2. The returned data is in JSON format, and my goal is to store it in a JSON object for further processing. While referring to the Angular2 documentation for guidance, I en ...

converting an angular object into a string representation

I stumbled upon this guide: . and it includes the following piece of code: import { Component } from '@angular/core'; import { FormGroup, FormControl } from '@angular/forms'; @Component({ selector: 'app-root', templateUrl ...

Sending a Thunk to the store using Typescript

Within my primary store.ts file, the following code is present: const store = createStore( rootReducer, composeWithDevTools(applyMiddleware(thunk)) ); store.dispatch(fetchUser()); Upon initial rendering, an action is dispatched to fetchUser in ord ...

Executing an HTTP POST request without properly encoding a specific parameter

I am attempting to communicate with an unauthorized third-party API using Node and the request module. Below is the code that generates the request: request.post( { url: url, headers: MY_HEADERS_HERE, followAllR ...

A Typescript object that matches types and eventually returns a string when called upon

In the process of overengineering a type that can match either a string or an object whose valueOf() function, when evaluated recursively, ultimately returns a string. type Stringable = string | StringableObject; interface StringableObject { valueOf() ...

A simple way to retrieve data from Firebase using the unique identifier (ID)

Hello, I am attempting to retrieve the user email for each message. Each message (chat) has a user ID associated with it. I fetch the entire user data using getUser on the *ngIf directive and then display the email address. It works fine and there are no ...

Error encountered in Angular 17 SSR: Importing module "@angular/ssr" does not have the exported member "REQUEST"

I'm having trouble getting cookies on Angular 17 with SSR. In the past, I was able to use the REQUEST pulled from @nguniversal/express-engine/tokens, but now with @angular/ssr, I can't find where to pull REQUEST from. import { REQUEST } from &apo ...

What is the best way to handle constants in TypeScript?

I am facing an issue with a React component I have created: const myComponent = ({constant}: Iprops) => ( <div> {CONSTANTS[constant].property ? <showThis /> : null </div> ) The error message says 'element implicitly has ...

Type 'ɵɵComponentDeclaration' must be provided with at least 7 but no more than 8 type arguments

Recently, in my project, I encountered an issue with the ng-particles v3.5.3 library on my login and sign-in pages. The problem arose suddenly and was displayed in my terminal as follows: Error: node_modules/ng-particles/lib/ng-particles.component.d.ts:18: ...

What are the steps to troubleshoot a Node Package Manager library in Visual Studio Code?

I have created a Typescript library that I plan to use in various NodeJS projects. The source code is included in the NPM package, so when I install it in my projects, the source also gets added to the node_modules folder. Now, during debugging, I want to ...

I'm having trouble retrieving the object value from a different function within my Typescript and Express application

Currently I am experimenting with utilizing typescript alongside express for my application development. I have created a function that I intend to utilize in various sections of my codebase. Upon invoking the function, I am able to observe the values thro ...

Utilizing interpolation for a CSS class defined in an external file within Angular 2

Is it feasible to send a variable to a CSS class in an external CSS file within Angular 2, such as: import { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', sty ...

Navigating the complexities of integrating Rollup, ES modules, TypeScript, and JSX can be a challenging endeavor due to

Lately, I've been learning about the tools mentioned in the title. However, I've encountered some bumps along the way, so I'm turning to StackOverflow for help. My Requirements I need something like Rollup to pack my stuff For bare module ...