如何创建api? [英] How to create an api?

查看:128
本文介绍了如何创建api?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建和API来连接Windows应用程序和Web应用程序。从Windows应用程序表单我喜欢将值传递给Web应用程序,并根据传递的值从Web应用程序检索值到Windows应用程序。

我在网上检查了很多页面,但我没有得到突破。



请指导我为实现这一目标所需的程序。



请帮帮我在这个。



提前致谢。



我尝试过:



我创建了一个Windows应用程序和一个Web应用程序。两个应用程序数据库都不同。

解决方案

从客户端删除数据库开始,当您使用Web API时,应该只维护一个数据源应用架构。除非您的数据源和网络(或CPU和硬件)延迟导致性能因素的巨大问题,否则不会使用多个数据源。



现在,问题是,ASP.NET已经支持Web API了。我假设您将ASP.NET MVC作为开发模式,如果是这样,只需将Web API包含在您的项目中。包含ASP.NET Web API包将允许您的应用程序具有单独的部分,用于API调用处理。



如何将Web API添加到现有的ASP.NET MVC 4 Web应用程序项目中? - 堆栈溢出 [ ^ ]



完成后,Web API使用相同的模式作为ASP.NET MVC。您可以为数据创建控制器,模型 - 它们可以是当前的 - 然后处理请求。每个请求都可以以JSON或XML格式返回数据。然后,您可以在客户端使用该数据来执行您想要的操作!



我想你会对我的文章感兴趣, ASP.NET 5 Web API RESTful CRUD和Windows 10本机应用程序 [ ^ ]


嗯,如果你不喜欢Afzaal Ahmad Zeeshan所说的任何东西,我会



创建一个REST服务器来从数据库中检索数据 - 这取决于你使用的技能/平台你可以看看Sinatra(Ruby),NancyFX(C#)这样做



然后使用从客户端到REST服务器公开的URI的HTTP调用,例如,以JSON的形式获取数据。



如果您以后想要REST服务器提供的不同数据元素,这会给您一些灵活性,它们只是不同的路由基于URI

I need to create and API to connect windows application and web application. From windows application form i like to a pass a value to web application and retrieves value from web application to windows application based on the passing value.
I check lot of pages in online but i didn't get a break through.

Please guide what ever the procedures that i need to do to achieve this.

Please help me on this.

Thanks in advance.

What I have tried:

I created one windows application and one web application. Both application database is different.

解决方案

Start by removing the database on the client-side, you should maintain just one data source when you are using a web API for your application architecture. There is no use of having multiple data sources, unless your data sources and network (or CPU and hardware) latency causes a huge trouble in performance factor.

Now, the thing is, ASP.NET already supports Web API. I assume that you are having ASP.NET MVC as the pattern for development, if so, just include Web API to your project. Inclusion of ASP.NET Web API package would allow your application to have a separate portion, for API calls handling.

How to add Web API to an existing ASP.NET MVC 4 Web Application project? - Stack Overflow[^]

Once that is done, Web API uses the same pattern as ASP.NET MVC. You create Controllers, Model(s) — they can be the current ones — for data, and then you handle the requests. Each request can return the data in JSON or XML format. You can then use that data on the client-side to perform what-you-want-to!

I guess you would be interested in my article, ASP.NET 5 Web API RESTful CRUDs and Windows 10 native application[^]


well, if you dont like anything Afzaal Ahmad Zeeshan has said, I would

Create a REST Server to retrieve data from the database - this depends on what skills/platform you are using, you could look at Sinatra (Ruby), NancyFX (C#) to do this

Then use a HTTP call from your client to the URI exposed by the REST server, get the data back as JSON for example.

This gives you some flexibility if you later want different data elements or such served by the REST Server, they are just different routes based on the URI


这篇关于如何创建api?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆