api格式_api平台支持的格式

本文探讨了API平台所支持的格式,包括不同编程语言如Python、Java和Linux下的处理方式,同时也涉及到与机器学习和Android应用的集成。
Python3.8

Python3.8

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

api格式

The API system has built-in content negotiation capabilities. By default, only the JSON-LD format is enabled. However, API Platform Core supports many more formats and can be extended.

API系统具有内置的内容协商功能。 默认情况下,仅启用JSON-LD格式。 但是, API Platform Core支持更多格式,并且可以扩展。

Available formats are: JSON-LD, GraphQL, JSON, JSON:API, HAL, XML, YAML, CSV, HTML (API docs).

可用格式为: JSON-LD,GraphQL,JSON,JSON:API,HAL,XML,YAML,CSV,HTML (API文档)

1. JSON-LD (1. JSON-LD)

Image for post

Data is messy and disconnected. JSON-LD organizes and connects it, creating a better Web.

数据混乱且断开连接。 JSON-LD进行组织和连接,从而创建一个更好的Web。

JSON-LD is a lightweight Linked Data format. It is easy for humans to read and write. It is based on the already successful JSON format and provides a way to help JSON data interoperate at Web-scale. JSON-LD is an ideal data format for programming environments, REST Web services, and unstructured databases such as Apache CouchDB and MongoDB.

JSON-LD是一种轻量级的链接数据格式。 人类易于阅读和书写。 它基于已经成功的JSON格式,并提供了一种方法来帮助JSON数据在Web规模上进行互操作。 JSON-LD是用于编程环境,REST Web服务和非结构化数据库(例如Apache CouchDB和MongoDB)的理想数据格式。

例; (Example;)

{
"@context": "https://json-ld.org/contexts/person.jsonld",
"@id": "http://dbpedia.org/resource/John_Lennon",
"name": "John Lennon",
"born": "1940-10-09",
"spouse": "http://dbpedia.org/resource/Cynthia_Lennon"
}

Linked Data empowers people that publish and use information on the Web. It is a way to create a network of standards-based, machine-readable data across Web sites. It allows an application to start at one piece of Linked Data, and follow embedded links to other pieces of Linked Data that are hosted on different sites across the Web.

链接数据可以使人们在Web上发布和使用信息。 这是一种跨网站创建基于标准的机器可读数据网络的方法。 它允许应用程序从一个链接数据段开始,并遵循嵌入的链接,这些链接指向托管在Web上不同站点上的其他链接数据段。

2. GraphQL (2. GraphQL)

A query language for your API

API的查询语言

Image for post

GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.

GraphQL是API的查询语言,是用于使用现有数据来完成这些查询的运行时。 GraphQL为您的API中的数据提供完整且易于理解的描述,使客户能够准确地询问他们所需的内容,仅此而已,使随着时间的推移更易于开发API并启用强大的开发人员工具。

Image for post

3. JSON (3. JSON)

Image for post

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language Standard ECMA-262 3rd Edition — December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.

JSON (JavaScript对象表示法)是一种轻量级的数据交换格式。 人类易于阅读和书写。 机器很容易解析和生成。 它基于JavaScript编程语言标准ECMA-262第三版(1999年12月)的子集。JSON是一种完全独立于语言的文本格式,但是使用C语言家族(包括C)的程序员熟悉的约定, C ++,C#,Java,JavaScript,Perl,Python等。 这些属性使JSON成为理想的数据交换语言。

JSON is built on two structures:

JSON建立在两种结构上:

  • A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.

    名称/值对的集合。 在各种语言中,这是作为对象 ,记录,结构,字典,哈希表,键列表或关联数组实现的。

  • An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.

    值的有序列表。 在大多数语言中,这是通过数组 ,向量,列表或序列实现的。

These are universal data structures. Virtually all modern programming languages support them in one form or another. It makes sense that a data format that is interchangeable with programming languages also be based on these structures.

这些是通用数据结构。 几乎所有现代编程语言都以一种或另一种形式支持它们。 可以与编程语言互换的数据格式也应基于这些结构,这是有道理的。

4. JSON API (4. JSON API)

A SPECIFICATION FOR BUILDING APIS IN JSON

在JSON中构建API的规范

Image for post

JSON API is a format that works with HTTP. It delineates how clients should request or edit data from a server, and how the server should respond to said requests. A main goal of the specification is to optimize HTTP requests; both in terms of the number of requests and the size of data packages exchanged between clients and servers. JSON API module exposes an implementation for data stores and data structures, such as entity types, bundles, and fields.

JSON API是可与HTTP一起使用的格式。 它描述了客户端应如何从服务器请求或编辑数据,以及服务器应如何响应所述请求。 该规范的主要目标是优化HTTP请求。 无论是请求数量还是客户端和服务器之间交换的数据包的大小。 JSON API模块公开了数据存储和数据结构的实现,例如实体类型,捆绑和字段。

5. HAL —超文本应用语言 (5. HAL — Hypertext Application Language)

HAL is a simple format that gives a consistent and easy way to hyperlink between resources in your API.

HAL是一种简单的格式,它提供了一种一致且简单的方法来在API中的资源之间建立超链接。

Adopting HAL will make your API explorable, and its documentation easily discoverable from within the API itself. In short, it will make your API easier to work with and therefore more attractive to client developers.

采用HAL将使您的API具有可探索性,并且可以轻松从API本身中发现其文档。 简而言之,它将使您的API易于使用,因此对客户端开发人员更具吸引力。

APIs that adopt HAL can be easily served and consumed using open source libraries available for most major programming languages. It’s also simple enough that you can just deal with it as you would any other JSON.

使用适用于大多数主要编程语言的开源库,可以轻松提供和使用采用HAL的API。 它也非常简单,您可以像处理其他任何JSON一样处理它。

HAL provides a set of conventions for expressing hyperlinks in either JSON or XML.

HAL提供了一组用于以JSON或XML表示超链接的约定。

Instead of using ad-hoc structures, or spending valuable time designing your own format; you can adopt HAL’s conventions and focus on building and documenting the data and transitions that make up your API.

不要使用临时结构,也不要花费宝贵的时间来设计自己的格式; 您可以采用HAL的约定,并专注于构建和记录构成API的数据和转换。

HAL is a little bit like HTML for machines, in that it is generic and designed to drive many different types of application via hyperlinks. The difference is that HTML has features for helping ‘human actors’ move through a web application to achieve their goals, whereas HAL is intended for helping ‘automated actors’ move through a web API to achieve their goals.

HAL有点像用于机器HTML,因为它是通用的,旨在通过超链接来驱动许多不同类型的应用程序。 区别在于HTML具有帮助“人类参与者”通过Web应用程序实现其目标的功能,而HAL旨在帮助“自动化参与者”通过Web API实现其目标。

Having said that, HAL is actually very human-friendly too. Its conventions make the documentation for an API discoverable from the API messages themselves. This makes it possible for developers to jump straight into a HAL-based API and explore its capabilities, without the cognitive overhead of having to map some out-of-band documentation onto their journey.

话虽如此, HAL实际上也非常人性化 。 它的约定使API文档可以从API消息本身中发现。 这使开发人员可以直接跳入基于HAL的API并探索其功能,而无需将一些带外文档映射到他们的旅程中,从而节省了认知开销。

Image for post

6.可扩展标记语言(XML) (6. Extensible Markup Language (XML))

Extensible Markup Language (XML) is a simple, very flexible text format derived from SGML (ISO 8879). Originally designed to meet the challenges of large-scale electronic publishing, XML is also playing an increasingly important role in the exchange of a wide variety of data on the Web and elsewhere.

可扩展标记语言(XML)是一种源自SGML(ISO 8879)的简单,非常灵活的文本格式。 XML最初旨在应付大规模电子出版的挑战,但在Web和其他地方交换各种数据方面也起着越来越重要的作用。

  • XML stands for eXtensible Markup Language

    XML代表可扩展标记语言
  • XML is a markup language much like HTML

    XML是类似于HTML的标记语言
  • XML was designed to store and transport data

    XML旨在存储和传输数据
  • XML was designed to be self-descriptive

    XML被设计为可自我描述的

7. YAML:YAML不是标记语言 (7. YAML: YAML Ain't Markup Language)

YAML is a human friendly data serialization standard for all programming languages. It is commonly used for configuration files and in applications where data is being stored or transmitted.

YAML是适用于所有编程语言的人类友好数据序列化标准。 它通常用于配置文件和用于存储或传输数据的应用程序。

8.逗号分隔值(CSV)文件 (8. Comma-Separated Values (CSV) Files)

The comma separated values format (CSV) has been used for exchangingand converting data between various spreadsheet programs for quitesome time. Surprisingly, while this format is very common, it hasnever been formally documented. Additionally, while the IANA MIMEregistration tree includes a registration for "text/tab-separated-values" type, no MIME types have ever been registered with IANA for CSV. At the same time, various programs and operating systems have begun to use different MIME types for this format.

逗号分隔值格式(CSV)已在相当长的一段时间内用于在各种电子表格程序之间交换和转换数据。 令人惊讶的是,尽管这种格式非常普遍,但从未正式记录过。 此外,虽然IANA MIMEregistration树包含“文本/制表符分隔值”类型的注册,但尚未向IANA注册CSV的MIME类型。 同时,各种程序和操作系统已开始对此格式使用不同的MIME类型。

9. HTML (API文档) (9. HTML (API docs))

HTML stands for Hyper Text Markup Language

HTML代表H yper T外部中号 arkup 大号 anguage

翻译自: https://medium.com/@biberogluyusuf/formats-supported-by-the-api-platform-35013626c79f

api格式

您可能感兴趣的与本文相关的镜像

Python3.8

Python3.8

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值