flask-RESTful与flask-RESTless,应在何时使用 [英] flask-RESTful vs flask-RESTless, which should be used, and when

查看:173
本文介绍了flask-RESTful与flask-RESTless,应在何时使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这两个库的主要区别是什么.就可用性和功能而言

如果您已经有大量的模型类,那么使用flask-restLESS非常有意义,对吗?如果仅靠烧瓶操作,它将缺少哪些功能.或者,烧瓶不安给您带来了什么,烧瓶不安所不能提供的??

解决方案

虽然我确定Flask-RESTful和Flask-RESTless之间将会有很大的重叠,但这是 orientation 据我所知:

Flask-RESTful旨在成为通用的,它是一种轻量级抽象,可与您现有的ORM/库一起使用".您的资源甚至都没有成为与数据库绑定的模型,并且可以是任何内容.

另一方面,Flask-RESTless明确表明其最佳用例是从SQLAlchemy模型创建简单的ReSTful JSON API"

因此,如果您有很多SQLAlchemy模型,并且其中需要相当标准的REST API,则可以使用Flask-RESTless加快开发速度,而只需最少的代码即可将模型公开到API中.

如果您具有自定义的端点,或者想使用不受SQLAlchemy支持的模型,则可以在Flask-RESTful上创建自己的模型

如何决定/或同时使用两者

您也可以使用足够的代码来自定义Flask-RESTless(序列化,自定义查询等).

例如问问自己您是否拥有更多结构化的基于模型的API或更多自定义API ,这将为您节省最多的开发时间,并且仅在出现特殊情况时进行处理. >

而且您可以在单个Flask应用中同时使用这两种功能,那里没有问题,例如将/api/resource-a/映射到Flask-RESTless API并将/api/resource-b/映射到另一个Flask-RESTful

What are the key differences of these two libraries.In terms of usability, and features

If you already have a huge number of model classes, using flask-restLESS makes perfect sense, right?. What are the features it would lack, if it would done with flask-restful. Or, what are flask-restful gives you, that flask restless can't provide.?

解决方案

While I'm sure there's going to be a significant of overlap between Flask-RESTful and Flask-RESTless, here's the difference in orientation as far as I can tell:

Flask-RESTful aims to be generic, it's a "lightweight abstraction that works with your existing ORM/libraries". Your resources don't even have to be a model tied to a database, and it could be anything.

On the other hand, Flask-RESTless makes it clear that their best use case is "creating simple ReSTful JSON APIs from SQLAlchemy models"

So if you have a lot of SQLAlchemy models and need fairly standard REST API from those, you can use Flask-RESTless to speed up the development, you need minimal code to expose your models into the API.

If you have custom endpoints, or want to use models that aren't backed by SQLAlchemy you can create your own on Flask-RESTful

How to decide / or use both

You can do customize Flask-RESTless too (serialization, custom queries etc), with sufficient code you can use either frameworks.

To decide e.g. ask yourself do you have more structured model-based APIs or more custom APIs, that would save you the most development time and only deal with special cases when they arise.

And You can use both in a single Flask app, no problems there, you just e.g. map /api/resource-a/ to a Flask-RESTless API and /api/resource-b/ to another API from made with Flask-RESTful

这篇关于flask-RESTful与flask-RESTless,应在何时使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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