问题标签 [api-design]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
java - 正确处理退货数据
我有一个与正确处理我正在为一个项目编写的 DAO 库的返回有关的问题。这个库可能会被其他人使用,我想正确地做到这一点。我应该如何处理我的 DAO 函数的返回语句?
示例 1 我有 getCustomer 函数,它应该返回字符串。如果查询没有返回任何结果,我应该返回 null、空字符串还是抛出某种异常?
示例 2
我有一个函数 ,getCutomerList
它返回一个 ArrayList<String> 类型的值。如果查询没有返回任何结果,我应该返回 null、空的 ArrayList 还是抛出一些异常?
示例 3
检测到一些 SQL 异常,我应该怎么做,抛出异常或对可能发生的块执行try
.. ?catch
适用于我的案例的“良好”做法或“最佳”做法是什么?
xml - 开源/免费的通用 EPG/XMLTV 数据 API 或服务,或者如何制作?
我正在寻找通用 EPG/XMLTV 服务的(开源,又名“免费”)数据源?
该项目需要以易于解析的格式更新/可更新的实时电视调度信息。它也必须免费提供或非常自由的许可证。感谢您提供任何建议或替代方案。
如果有人对从哪里开始有一些建议,我愿意编写自己的解决方案。
api-design - API 端点语义
API 端点是“方法”,例如https://api.foursquare.com/v2/venues/还是包含非查询字符串参数的完整 URL,例如 https://api.foursquare.com/v2/venues/ 5104
换句话说,这两个独立的端点还是被认为是同一个端点?
http://myapi.com/somemodel/1
http://myapi.com/somemodel/2
c++ - 在 C++ API 上公开的基本类型
我的目标是 Windows,但我看不出为什么我正在编写的某些 API 代码不能使用基本的 C++ 类型。我想要做的是公开返回字符串和整数的方法。在 C# 世界中,我只使用字符串,并拥有一个 unicode 字符串,但在 VC++ 中,我可以选择使用 std::string、std::wstring 或 MFC/ATL CStrings。
我应该只使用 std::wstring 来支持 unicode,还是可以使用 std::string 根据我的构建设置编译为 unicode?我倾向于后者。我更愿意在我的对象上为其他字符串类型提供 Get[Item]AsCString() 方法。
我还应该使用 size_t 而不是整数吗?
该 API 将由我使用,也许未来的开发人员将使用 C++ GUI。这是一种分离关注点的方法。我的偏好:
- 对其他开发人员的直观性。
- 与 VC++ 的前向兼容性
- 与其他 C++ 编译器的兼容性
- 性能(这对我来说不太重要,但我的应用程序的其余部分需要启动时间)
任何指南将不胜感激。
c++ - 在命名空间声明之后声明 using 语句
我正在编写一个由几个“包”组成的实用程序库。每个包中的类都包含在不同的命名空间中。我知道如何通过在类声明的末尾自动声明 using 语句来简化这种情况(见下文),这将避免程序员在 cpp 文件中执行此操作。
我的理解是,如果用户包含标题 String.h 并且 String 在 Utility 中,那么程序员会想要使用 String。显然,如果有外部类链包括一堆弄脏命名空间的文件,这可能会很糟糕,所以我想如何将其改为#define。
这样,想要这种扩展功能的程序员就可以得到它。
这是一个好主意还是我忽略了什么?
c++ - 包括所有内容,用“使用”分隔
我正在开发一个 C++ 库。它让我想到了 Java 和 C# 处理包括库的不同组件的方式。例如,Java 使用“import”来允许使用来自其他包的类,而 C# 只是使用“using”来导入整个模块。
我的问题是,将库中的所有内容#include 到一个大型包含中然后只使用 using 指令来导入特定的类和模块是一个好主意吗?或者这会变得很疯狂吗?
编辑: 到目前为止反应良好,这里有一些缓解因素,我觉得这些因素会增加这个想法:
1)内部#includes 保持正常(简短而重要)
2)包含所有内容的文件可以选择与库一起提供给希望使用它的人
3)您可以选择将大包含文件作为 pre 的一部分- 编译的头文件
.net - 我应该在我的域模型中使用 System.Net.Mail.MailAddress,还是只使用字符串?
正如这个问题中所涵盖的那样,System.Uri
是反映我对 URI 的意图的好选择。但是电子邮件地址呢?
它似乎不那么明确,因为MailAddress
它的属性中有额外的信息,DisplayName
不是很合适。
http - 使用 HTTPS 时 OAuth 是否无关紧要?
我正在设计一个 RESTful API,它将始终通过 HTTPS 进行通信。在 HTTPS 上运行时是否有任何理由使用像 OAuth 这样的方案?我特别感兴趣的是,当整个通信被加密时,HMAC 签名的请求、随机数和时间戳等方面是否有用。
似乎任何通过 HTTPS 的身份验证方案都足够了,但我只是想获得第二意见。
perl - perl-selenium: how to extend Test::WWW::Selenium object with custom methods?
Using perl and TAP, I have written a lot of selenium tests and saved them in *.t files.
I have created some helper functions, put them into a non-object oriented package, say My::Util::SeleniumHelper.
All functions are exported from this module. In the beginning, one package was sufficient, now the single-module API contains quite a few unrelated functions. These functions are called, for example make_sel(), head_ok(), cms_logout(), cms_login(), cms_clickthru_simple(), selenium_rc_running(), treecontrol_toggles() - you get the idea.
Moreover, many blocks of code in the t-files are still redundant, making the .t file look like a template.
Thus, I want to give my *.t code a more OO design.
Any ideas on how to design the new API?
Essentially, I am also looking for code examples (here, or on the internet) where someone has extended the selenium object in a clever way. It does not have to be in perl.
Would it be useful to add methods to the Test::WWW::Selenium object $sel?
I should I try to override the $sel object?, Deriving a Test::WWW::Selenium::Customized class from Test::WWW::Selenium
This would violate the "Prefer composition over inheritance" idiom
Should I wrap the selenium object into another object using composition?
Here are some more requirements or thoughts:
I also want to use the pageObjects Pattern/Idiom. Not doing so yet. Maybe so
or
I noted that in most cases, basically, I'd like to give the selenium method something like an Moose's around() modifier. Do th standard thing, but do some things before and after.
However, I prefer to not use Moose here because the tests need to run on a few different machines, and don't want to install Moose and all its dependencies on all these PCs. I am not saying that is impossible to use moose, however I did not yet use non-moose objects (Test::WWW::Selenium) and moose objects together.
asp.net-mvc - MVC Web UI 和 API 设计问题 - 新的视图模型还是使用现有的?
我最近遇到了为现有 Web 门户创建 API 的需求。当前的 Web UI 将保持原样,API 将为希望在核心应用程序之上构建应用程序的任何客户端提供额外的功能。
Web ui 非常复杂,由几个逐步完成的表单组成,以实现所需的功能。例如,某些域对象以类似向导的方式拆分为一组表单视图(我的视图模型)。输入的值是否为 int、给定的电子邮件是否有效等方面的验证发生在视图模型上。
我打算重新使用 viewmodel 类来表示 api 中的用户输入。
例如 WebUI: public ActionResult Save(FormOne form){...} API: public ActionResult Save(String apiKey, FormOne form){...}
但这太难了,即在 WebUI 视图模型和 API 视图模型之间有一个完美的映射。
在这种情况下,什么是好的设计?
a) 为 API 创建一个新的视图模型?b) 尽可能使用现有的视图模型 - 在适当的情况下创建新类 c) 其他?
谢谢, Y