为我的软件创建 API - 基本代码结构 [英] Creating an API for my software - Basic code structure

查看:21
本文介绍了为我的软件创建 API - 基本代码结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在编写一个 Web 软件,客户端桌面也将通过 API 使用该软件.我现在面临的问题是:我是否应该两次在应用程序中执行添加/更新/删除对象的每个操作?一次是在普通代码中,一次是为 API 隔离?

I'm currently writing a web software which is also going to be used by Client desktops via an API. The problem I'm facing right now is: Should I implement every action of adding/updating/deleting objects in the application twice? Once as it sits in the normal code and once isolated for the API?

或者我更应该使用一个 OOP 模型类系统来代表我数据库中的所有对象,并将它们用于 API 和普通代码?

Or should I much rather use a system of OOP model classes that represent all objects in my database and use those for both the API and normal code?

或者直接开发 API 并从我的普通 Web 界面中使用它?

Or develop the API first hand and use it from my normal web interface too?

这是我一直想知道的.提前致谢!

This is something I have always wondered about. Thanks in advance!

推荐答案

做两次事情几乎总是一个坏主意——你最好实现 API,向最终用户开放它,并使用它也用于客户端代码,并为特定于接口的内容添加了一些额外的钩子.

Doing things twice is almost always a bad idea -- you're probably better off implementing the API, opening it up to the end-user, and also using it for the client code as well, with some extra hooks for stuff that is interface-specific.

这篇关于为我的软件创建 API - 基本代码结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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