fab / web-service
灵活获取数据的Web服务。可能的输出格式:JSON、Atom、HTML。此Web服务仅用于检索数据。
0.2.0
2018-07-20 13:19 UTC
Replaces
- typo3-ter/web-service: 0.2.0
- web_service: 0.2.0
README
这是一个为TYPO3 CMS设计的扩展,旨在以灵活的方式查询数据。可能的输出格式:JSON、Atom、RSS。
提供的示例URL已被编码。
# Return all FE user group
http://domain.tld/content/usergroups
# Return all FE users - authentication required
http://domain.tld/content/users
# Return latest FE users login - authentication required
http://domain.tld/content/last-login
# Return one FE user with id "1"
http://domain.tld/content/users/1
# Return the frontend group related to user "1" (no yet implemented!!)
http://domain.tld/content/users/1/groups
支持五种输出格式:atom、csv、html、json、xml。默认为JSON。
# Configure the output format - atom, csv, html, json, xml
http://domain.tld/content/users.xml
在底层,URL被解码并对应于类似以下的内容:
http://domain.tld/index.php?eID=web_service&route=users/1;
此Web服务旨在检索数据,是只读的,因此(至少目前)不提供PUT、POST、DELETE、PATCH方法。
配置
配置通过TypoScript完成。对于新的内容类型,您必须注册一个新的键,例如“users”或“usergroups”,正如在URL http://domain.tld/content/users
中使用的那样。
plugin.tx_webservice {
settings {
mappings {
# Required key for a new content type
users {
# Required value!
tableName = fe_users
# Tell the maximum items taken by default for the list.
limit = 50
# Optional default filters (not yet implemented)
filter =
# Protect the output with a token or a user session
permissions {
# Possible comma separated list of Frontend User group.
frontendUserGroups = *
# Give a general uuid token to protect this data stream
#token = 3ce2b796-69cd-11e6-8b77-86f30ca893d3
}
# The fields being display in the list.
# http://domain.tld/content/users
many {
fields = uid, first_name, last_name
}
# The fields being display in the detail.
# http://domain.tld/content/users/1
one {
fields = uid, first_name, last_name, usergroup
}
}
last-login < .users
last-login {
# Default ordering which will override the "default_sortby" in the TCA
orderings {
lastlogin = DESC
}
# Tell the maximum items taken by default for the list.
limit = 10
}
# Stream frontend user group information
usergroups {
# Required value!
tableName = fe_groups
# In this example we take every fields of fe_groups excpect those ones
excludedFields = felogin_redirectPid, tx_extbase_type, TSconfig, lockToDomain, subgroup
# Default ordering which will override the "default_sortby" in the TCA
orderings {
title = ASC
}
}
}
# Specific configuration for format "atom". In this case we really want to limit the number of items.
atom {
limit = 10
}
}
}
安装
-
通过composer安装或克隆扩展到/path/typo3conf/ext/。
$ composer require fab/web-service
-
转到扩展管理器并激活扩展web_service。
-
向您的 .htaccess 添加重写规则
RewriteRule ^content/(.*)$ /index.php?eID=web_service&route=$1 [QSA,L]
或者,如果您使用Nginx
rewrite ^/content/(.*)$ /index.php?eID=web_service&route=$1 last;
现在您可以使用content/
开始获取内容。