精通Python构建RESTful Web服务

4星 · 超过85%的资源 需积分: 10 161 下载量 137 浏览量 更新于2024-07-19 4 收藏 10.71MB PDF 举报
"Building RESTful Python Web Services" 是一本专为全球广泛使用的Python开发者设计的书籍,旨在教授如何利用Python构建RESTful架构的高质量Web服务。这本书将介绍Python、Django、Flask和Tornado等流行的框架以及相关的库和工具,帮助读者掌握开发RESTful API的技能。 书中详细探讨了每个框架,包括它们在构建不同Web服务中的应用,提供了何时选择特定框架以获得最佳效果的案例和最佳实践。作者Gastón C. Hillar通过深入讲解以下关键概念和技术,确保读者能够成功地开发RESTful API: 1. 请求处理:理解如何处理HTTP请求,包括GET、POST、PUT、DELETE等操作。 2. URL映射:学习如何将URL与特定的视图函数关联,以处理不同的请求路径。 3. 序列化:将Python对象转换为JSON或其他可跨网络传输的格式,以便客户端能理解和使用。 4. 验证:验证接收到的数据的有效性,确保数据的安全和准确。 5. 认证:实现用户身份验证机制,如令牌认证或OAuth2,保护API资源不被未授权访问。 6. 授权:控制不同用户对资源的访问权限,实现细粒度的权限管理。 7. 版本控制:处理API版本升级,确保向后兼容性。 8. ORM(对象关系映射):使用如SQLAlchemy等库简化数据库操作。 9. 数据库:了解如何与各种数据库(如SQLite、MySQL、PostgreSQL等)集成。 10. 自定义模型和视图代码:根据需求编写定制的业务逻辑。 11. 异步回调:使用Tornado等框架实现非阻塞I/O,提高Web服务的性能和可扩展性。 在每个框架部分的结尾,作者会介绍如何为RESTful API添加安全性和认证功能,并编写测试用例以确保API的稳定性和可靠性。此外,尽管书中的信息尽可能准确,但读者应意识到编程领域的发展速度很快,出版时的信息可能已经有所更新。因此,读者在实际应用中还需结合最新的技术动态和文档进行学习。 本书适合有一定Python基础并希望提升到Web服务开发领域的读者,无论是初学者还是经验丰富的开发者,都能从中受益,掌握构建轻量、可维护、可扩展且安全的RESTful Python Web服务的知识和技巧。
2016-12-29 上传
Create web services that are lightweight, maintainable, scalable, and secure using the best tools and techniques designed for Python About This Book Develop RESTful Web Services using the most popular frameworks in Python Configure and fine-tune your APIs using the best tools and techniques available This practical guide will help you to implement complete REST-based APIs from scratch Who This Book Is For This book is for web developers who have working knowledge of Python and would like to build amazing web services by taking advantage of the various frameworks of Python. You should have some knowledge of RESTful APIs. What You Will Learn Develop complex RESTful APIs from scratch with Python combined with and without data sources Choose the most appropriate (micro) framework based on the specific requirements of a RESTful API / web service Debug, test, and profile RESTful APIs with each of the frameworks Develop a complex RESTful API that interacts with a PostgreSQL database Add authentication and permissions to a RESTful API built in each of the frameworks Map URL patterns to request handlers and check how the API works Profile an existing API and refactor it to take advantage of asynchronous code In Detail Python is the language of choice for millions of developers worldwide, due to its gentle learning curve as well as its vast applications in day-to-day programming. It serves the purpose of building great web services in the RESTful architecture. This book will show you the best tools you can use to build your own web services. Learn how to develop RESTful APIs using the popular Python frameworks and all the necessary stacks with Python, Django, Flask, and Tornado, combined with related libraries and tools. We will dive deep into each of these frameworks to build various web services, and will provide use cases and best practices on when to use a particular framework to get the best results. We will show you Table of Contents Chapter 1. Developing RESTful APIs with Django Chapter 2. Working with Class-Based Views and Hyperlinked APIs in Django Chapter 3. Improving and Adding Authentication to an API With Django Chapter 4. Throttling, Filtering, Testing, and Deploying an API with Django Chapter 5. Developing RESTful APIs with Flask Chapter 6. Working with Models, SQLAlchemy, and Hyperlinked APIs in Flask Chapter 7. Improving and Adding Authentication to an API with Flask Chapter 8. Testing and Deploying an API with Flask Chapter 9. Developing RESTful APIs with Tornado Chapter 10. Working with Asynchronous Code, Testing, and Deploying an API with Tornado Chapter 11. Exercise Answers