使用包创建 RESTful API 接口有什么好处 [英] Whats the advantage of using a package to create a RESTful API interface

查看:27
本文介绍了使用包创建 RESTful API 接口有什么好处的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的一个应用程序上创建一个简单的 RESTful 界面,我一直在查看可用的内容:

I am creating a simple RESTful interface on one of my apps and I have been looking at what's available out there:

我看过:

  • django-piston but it seems abandoned and the feedback on it is not great.
  • django-dynamicresponse which seems rather bare
  • A lot of packages from here

然而,看看这些包的例子,它们似乎并没有真正提供多少.创建一个 URL 映射列表并使用 simplejson 之类的东西来返回响应真的不难...

However, looking at examples of how these packages it seems that they don't really provide much. It's really not that hard to create a list of URL mappings and use something like simplejson to return a response...

使用我缺少的这些软件包之一是否有优势?

Is there an advantage to using one of these packages that I am missing?

这个问题可能与 Django 和 Restful APIs 类似,但已经有一段时间了那个人有任何新的答案,我想知道是否值得使用一个包.

This question may be similar to Django and Restful APIs but it has been a while since that one had any new answers, and I want to find out whether it is worth to use a package at all.

谢谢

推荐答案

如果您正在为一两个简单模型编写一个 API 以供内部"使用(例如,为了您的应用程序的 AJAX 前端与后端进行通信,. 暴露给外部客户端的 API),那么与编写一两个视图并使用 simplejson 相比,像 django-piston 或 Tastypie 这样的框架可能有点矫枉过正.

If you are writing one API for one or two simple models for "internal" use (eg, for the AJAX frontend of your app to communicate with the backend vs. an API exposed to external clients), then frameworks like django-piston or Tastypie might be overkill compared to writing one or two views and using simplejson.

当您有更复杂的需求时,框架才开始真正发挥作用.一些例子:

Where the frameworks start to really pull their own weight is when you have more complicated requirements. Some examples:

  • 你有一个包含很多关系的复杂模型(想想嵌套树结构)
  • 除了 JSON,您还需要支持多种序列化(XML、YAML、Plists 或 JSONP)
  • 您想对 API 进行版本控制
  • 您想限制某些操作的访问权限(例如,为某些客户端提供只读访问权限)
  • 您想限制或限制客户端访问

在您控制两端的小型简单项目中,其中许多都不是什么大问题,但是当您考虑为您的服务制作外部 API 时变得非常重要.

Many of those aren't a big deal on a small, simple project where you control both ends, but become very important when you're thinking about making an external API to your service.

这篇关于使用包创建 RESTful API 接口有什么好处的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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