简体   繁体   English

如何交流使用C编程开发的AngularJS的$ http路由和API

[英]How to communicate AngularJS's $http routes and APIs developed in C Programming

I have made web application GUI using AngularJS, Bootstrap, HTML, CSS. 我已经使用AngularJS,Bootstrap,HTML,CSS制作了Web应用程序GUI。 Backend team are developing APIs in C Programing. 后端团队正在开发C编程API。

So how my routes in $http request (sending from factory) will communicate to C Programing API (Controller) to get data or to perform related operations. 因此,我在$ http请求中发送的路由(从工厂发送)将如何与C编程API(控制器)通信以获取数据或执行相关操作。

Thanks! 谢谢!

You would just need the URI and the Async request would look like this: 您只需要URI,Async请求将如下所示:

    $http.get('URI goes here').then(
            function (response) {
                //success
                vm.data = response;
            },
            function (response) {
                //fail
                console.log("error");
            }
        );

I think you need to learn the concepts of Web API's. 我认为您需要学习Web API的概念。 Basically the server (C written in your case?) responds to various HTTP requests (GET, POST, PUT, etc..). 基本上,服务器(用您的情况编写的C吗?)响应各种HTTP请求(GET,POST,PUT等)。 By defining a Web API you simply state that for some http request for a specific path - there's gonna be a meaningful response. 通过定义Web API,您只需声明针对特定路径的某些http请求-就会得到有意义的响应。

For example here's a Web API: 例如,这是一个Web API:

GET /api/users - list users
GET /api/users/{id} - get a specific user
POST /api/users/{id} - update specific user

To consume this endpoint ( /api/users ) you can use $resource or $http like so: 使用此端点( /api/users ),可以使用$resource$http如下所示:

var UserFactory = $resource('/api/users/:id');
var userlist = UserFactory.query();
var user = UserFactory.get({id: 123});
user.$promise.then(function(){
 user.balance = 100000000;
 user.$save();
});

Basically in the background angular translates $resource calls to HTTP requests. 基本上在后台,angular将$resource调用转换为HTTP请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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