如何链接快速API和角形式

发布于 2025-02-10 18:41:08 字数 227 浏览 1 评论 0原文

我是新来的快速API,我对此一无所知,现在我想使用它进行小型应用程序。

我有一个用Angular创建的表单,我想在所有信息完成后向我展示下面的文本。现在的问题是我不知道如何将其与快速API链接,以便我可以将数据发送到Web服务器,然后在我的表单下方显示消息。

目的是了解快速API如何与Angular一起使用。

请有人建议一个解释这一点的教程..我搜索但没有找到我想要的。

先感谢您。

I'm new to fast api I really know nothing about it, and now I want to do a small application using it.

I have a form created with Angular and I want to show me a text below the form when all the information are completed. The problem now is I don't know how to link it with fast api so that i can send the data to web server then show a message below my form.

The purpose is understanding how does fast api work with angular especially.

Please can someone suggest a tutorial that explain that .. I searched but didn't find what I want.

Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人生百味 2025-02-17 18:41:08

就像上面提到的Matslidnh一样。 Fastapi没什么特别的。

您需要创建服务来处理HTTP请求。并随时随地使用它。

httprequest的服务示例。

import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { map } from 'rxjs/operators';

@Injectable({
  providedIn: 'root'
})
export class ApiService {


  private REST_API_SERVER = "http://localhost:8000/"; //url of your BE
  constructor(private httpClient: HttpClient) { }

  getTypeRequest(url) {
    return this.httpClient.get(this.REST_API_SERVER+url).pipe(map(res => {
      return res;
    }));
  }

  postTypeRequest(url, payload) {
    return this.httpClient.post(this.REST_API_SERVER+url, payload).pipe(map(res => {
      return res;
    }));
  }

  putTypeRequest(url, payload) {
    return this.httpClient.put(this.REST_API_SERVER+url, payload).pipe(map(res => {
      return res;
    }))
  }  
}

Y like MatsLidnh mention above. There is nothing special about FastApi.

You need to create service to handle http request. And use it whenever you wants.

Example of service for HttpRequest.

import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { map } from 'rxjs/operators';

@Injectable({
  providedIn: 'root'
})
export class ApiService {


  private REST_API_SERVER = "http://localhost:8000/"; //url of your BE
  constructor(private httpClient: HttpClient) { }

  getTypeRequest(url) {
    return this.httpClient.get(this.REST_API_SERVER+url).pipe(map(res => {
      return res;
    }));
  }

  postTypeRequest(url, payload) {
    return this.httpClient.post(this.REST_API_SERVER+url, payload).pipe(map(res => {
      return res;
    }));
  }

  putTypeRequest(url, payload) {
    return this.httpClient.put(this.REST_API_SERVER+url, payload).pipe(map(res => {
      return res;
    }))
  }  
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文