简体   繁体   中英

Can I make all API request from the server side in angular universal?

I added angular universal to my angular project and I want to now ensure that all post and get api request are done from the server side and not the client side. Is it posible to achieve this in angular?

Form Instance, I have a form for posting data to the backend. When the user submit the form, I want the post reqest to be done from the backend and not from the the client side?

I want this request to be made from the backend

onSubmit(){
    this.http.post('https://jsonplaceholder.typicode.com/posts', this.testForm.value)
    .subscribe(res=>{
     //Some response 
    })
  }

Angular Universal is not meant to do HTTP request once the client side has loaded or make HTTP requests besides GET for hydrating the view.

You can make an HTTP GET request to fetch data and then transfer the state to the client side. However, per user authorization and authentication with cookies or such won't work on the server side.

Every other requests that happen after the bootstraping of the application are and should be done from the client side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM