使用包创建RESTful API接口的优点是什么? [英] Whats the advantage of using a package to create a RESTful API interface

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

问题描述

我在其中一个应用程序上创建了一个简单的RESTful界面,我一直在寻找可用的内容:



我看过:





然而,看看这些包似乎没有提供太多的例子。创建URL映射列表并使用像simplejson这样的东西来返回响应确实并不困难。



使用这些软件包之一是有利的我失踪了?



这个问题可能类似于 Django和Restful API ,但已经有一段时间了,因为有一个新的答案,我想知道是否值得使用一个包。



谢谢

解决方案

如果您为内部使用的一个或两个简单模型编写了一个API(例如,为了与应用程序的AJAX前端通讯,与外部客户端的API进行通信),那么与编写一个或两个视图并使用simplejson相比,像django-piston或Tastypie这样的框架可能会比较过分。



当您有更复杂的要求时,框架开始真正拉动自己的重量。一些例子:




  • 你有一个很多关系的复杂模型(认为嵌套树结构)

  • <您需要支持多个序列化(XML,YAML,Plists或JSONP除JSON之外)
  • 您要对您的API进行版本

  • 您想要限制某些操作的访问(例如,为某些客户端提供只读访问权限)

  • 您要限制或限制客户端访问



许多这些在一个简单的小型项目中并不是一件大事,您可以控制两端,但是当您考虑外部设计时会变得非常重要API到您的服务。


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

I've looked at:

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?

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.

Thanks

解决方案

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:

  • you have a complicated model with a lot of relations (think nested tree structures)
  • you need to support multiple serializations (XML, YAML, Plists, or JSONP in addition to JSON)
  • you want to version your API
  • you want to do restrict access for some operations (eg, to provide read-only access to certain clients)
  • you want to throttle or rate-limit client access

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天全站免登陆