pop-api / api
基于组件的API
Requires
- php: ^8.1
- getpop/engine: ^5.0
Requires (Dev)
- getpop/access-control: ^5.0
- getpop/cache-control: ^5.0
- phpstan/phpstan: ^1.8
- phpunit/phpunit: ^10.2
- rector/rector: ^0.18
- squizlabs/php_codesniffer: ^3.6
Suggests
- getpop/access-control: Integration with Access Control
- getpop/cache-control: Integration with Cache Control
Conflicts
- gatographql/external-dependency-wrappers: <5.0.0
- gatographql/gatographql: <5.0.0
- gatographql/plugin-utils: <5.0.0
- gatographql/testing-schema: <5.0.0
- getpop/access-control: <5.0.0
- getpop/cache-control: <5.0.0
- getpop/component-model: <5.0.0
- getpop/componentrouting: <5.0.0
- getpop/definitions: <5.0.0
- getpop/dom-crawler: <5.0.0
- getpop/engine-wp: <5.0.0
- getpop/engine-wp-bootloader: <5.0.0
- getpop/filestore: <5.0.0
- getpop/graphql-parser: <5.0.0
- getpop/guzzle-http: <5.0.0
- getpop/loosecontracts: <5.0.0
- getpop/mandatory-directives-by-configuration: <5.0.0
- getpop/markdown-convertor: <5.0.0
- getpop/root: <5.0.0
- getpop/root-wp: <5.0.0
- graphql-by-pop/graphiql: <5.0.0
- graphql-by-pop/graphql-clients-for-wp: <5.0.0
- graphql-by-pop/graphql-endpoint-for-wp: <5.0.0
- graphql-by-pop/graphql-request: <5.0.0
- graphql-by-pop/graphql-server: <5.0.0
- graphql-by-pop/graphql-voyager: <5.0.0
- phpunit-for-gatographql/dummy-schema: <5.0.0
- phpunit-for-gatographql/dummy-wp-schema: <5.0.0
- phpunit-for-gatographql/gatographql: <5.0.0
- phpunit-for-gatographql/gatographql-testing: <5.0.0
- phpunit-for-gatographql/webserver-requests: <5.0.0
- phpunit-for-gatographql/wpfaker-schema: <5.0.0
- pop-api/api-clients: <5.0.0
- pop-api/api-endpoints: <5.0.0
- pop-api/api-endpoints-for-wp: <5.0.0
- pop-api/api-graphql: <5.0.0
- pop-api/api-mirrorquery: <5.0.0
- pop-api/api-rest: <5.0.0
- pop-backbone/php-hooks: <5.0.0
- pop-backbone/wp-data-parser: <5.0.0
- pop-cms-schema/categories: <5.0.0
- pop-cms-schema/categories-wp: <5.0.0
- pop-cms-schema/category-mutations: <5.0.0
- pop-cms-schema/category-mutations-wp: <5.0.0
- pop-cms-schema/comment-mutations: <5.0.0
- pop-cms-schema/comment-mutations-wp: <5.0.0
- pop-cms-schema/commentmeta: <5.0.0
- pop-cms-schema/commentmeta-wp: <5.0.0
- pop-cms-schema/comments: <5.0.0
- pop-cms-schema/comments-wp: <5.0.0
- pop-cms-schema/custompost-categories-wp: <5.0.0
- pop-cms-schema/custompost-category-mutations: <5.0.0
- pop-cms-schema/custompost-category-mutations-wp: <5.0.0
- pop-cms-schema/custompost-mutations: <5.0.0
- pop-cms-schema/custompost-mutations-wp: <5.0.0
- pop-cms-schema/custompost-tag-mutations: <5.0.0
- pop-cms-schema/custompost-tag-mutations-wp: <5.0.0
- pop-cms-schema/custompost-tags-wp: <5.0.0
- pop-cms-schema/custompost-user-mutations: <5.0.0
- pop-cms-schema/custompost-user-mutations-wp: <5.0.0
- pop-cms-schema/custompostmedia: <5.0.0
- pop-cms-schema/custompostmedia-mutations: <5.0.0
- pop-cms-schema/custompostmedia-mutations-wp: <5.0.0
- pop-cms-schema/custompostmedia-wp: <5.0.0
- pop-cms-schema/custompostmeta: <5.0.0
- pop-cms-schema/custompostmeta-wp: <5.0.0
- pop-cms-schema/customposts: <5.0.0
- pop-cms-schema/customposts-wp: <5.0.0
- pop-cms-schema/media: <5.0.0
- pop-cms-schema/media-mutations: <5.0.0
- pop-cms-schema/media-mutations-wp: <5.0.0
- pop-cms-schema/media-wp: <5.0.0
- pop-cms-schema/menus: <5.0.0
- pop-cms-schema/menus-wp: <5.0.0
- pop-cms-schema/meta: <5.0.0
- pop-cms-schema/metaquery-wp: <5.0.0
- pop-cms-schema/page-mutations: <5.0.0
- pop-cms-schema/page-mutations-wp: <5.0.0
- pop-cms-schema/pagemedia-mutations: <5.0.0
- pop-cms-schema/pages: <5.0.0
- pop-cms-schema/pages-wp: <5.0.0
- pop-cms-schema/post-categories: <5.0.0
- pop-cms-schema/post-categories-wp: <5.0.0
- pop-cms-schema/post-category-mutations: <5.0.0
- pop-cms-schema/post-mutations: <5.0.0
- pop-cms-schema/post-tag-mutations: <5.0.0
- pop-cms-schema/post-tags: <5.0.0
- pop-cms-schema/post-tags-wp: <5.0.0
- pop-cms-schema/postmedia-mutations: <5.0.0
- pop-cms-schema/posts: <5.0.0
- pop-cms-schema/posts-wp: <5.0.0
- pop-cms-schema/queriedobject: <5.0.0
- pop-cms-schema/queriedobject-wp: <5.0.0
- pop-cms-schema/schema-commons: <5.0.0
- pop-cms-schema/schema-commons-wp: <5.0.0
- pop-cms-schema/settings: <5.0.0
- pop-cms-schema/settings-wp: <5.0.0
- pop-cms-schema/tag-mutations: <5.0.0
- pop-cms-schema/tag-mutations-wp: <5.0.0
- pop-cms-schema/tags: <5.0.0
- pop-cms-schema/tags-wp: <5.0.0
- pop-cms-schema/taxonomies: <5.0.0
- pop-cms-schema/taxonomies-wp: <5.0.0
- pop-cms-schema/taxonomy-mutations: <5.0.0
- pop-cms-schema/taxonomy-mutations-wp: <5.0.0
- pop-cms-schema/taxonomymeta: <5.0.0
- pop-cms-schema/taxonomymeta-wp: <5.0.0
- pop-cms-schema/taxonomyquery: <5.0.0
- pop-cms-schema/taxonomyquery-wp: <5.0.0
- pop-cms-schema/user-avatars: <5.0.0
- pop-cms-schema/user-avatars-wp: <5.0.0
- pop-cms-schema/user-roles: <5.0.0
- pop-cms-schema/user-roles-wp: <5.0.0
- pop-cms-schema/user-state: <5.0.0
- pop-cms-schema/user-state-mutations: <5.0.0
- pop-cms-schema/user-state-mutations-wp: <5.0.0
- pop-cms-schema/user-state-wp: <5.0.0
- pop-cms-schema/usermeta: <5.0.0
- pop-cms-schema/usermeta-wp: <5.0.0
- pop-cms-schema/users: <5.0.0
- pop-cms-schema/users-wp: <5.0.0
- pop-schema/directive-commons: <5.0.0
- pop-schema/extended-schema-commons: <5.0.0
- pop-schema/http-requests: <5.0.0
- pop-schema/schema-commons: <5.0.0
- pop-wp-schema/block-content-parser: <5.0.0
- pop-wp-schema/blocks: <5.0.0
- pop-wp-schema/commentmeta: <5.0.0
- pop-wp-schema/comments: <5.0.0
- pop-wp-schema/custompostmeta: <5.0.0
- pop-wp-schema/customposts: <5.0.0
- pop-wp-schema/media: <5.0.0
- pop-wp-schema/menus: <5.0.0
- pop-wp-schema/meta: <5.0.0
- pop-wp-schema/multisite: <5.0.0
- pop-wp-schema/pages: <5.0.0
- pop-wp-schema/posts: <5.0.0
- pop-wp-schema/schema-commons: <5.0.0
- pop-wp-schema/settings: <5.0.0
- pop-wp-schema/site: <5.0.0
- pop-wp-schema/taxonomymeta: <5.0.0
- pop-wp-schema/usermeta: <5.0.0
- pop-wp-schema/users: <5.0.0
- dev-master / 5.0.x-dev
- 5.0.0
- 4.2.0
- 4.1.1
- 4.1.0
- 4.0.1
- 4.0.0
- 3.0.0
- 2.6.1
- 2.6.0
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.1
- 2.4.0
- 2.3.0
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.1
- 2.0.0
- 1.6.0
- 1.5.5
- 1.5.4
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.0
- 1.3.1
- 1.3.0
- 1.2.0
- 1.1.1
- 1.1.0
- 1.0.15
- 1.0.14
- 1.0.13
- 1.0.12
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- 0.10.2
- 0.10.1
- 0.10.0
- 0.9.10
- 0.9.9
- 0.9.8
- 0.9.7
- 0.9.6
- 0.9.5
- 0.9.4
- 0.9.3
- 0.9.2
- 0.9.1
- 0.9.0
- 0.8.9
- 0.8.8
- 0.8.7
- 0.8.6
- 0.8.5
- 0.8.4
- v0.8.3
- v0.8.2
- 0.8.1
- 0.7.13
- 0.7.12
- 0.7.11
- 0.7.10
- 0.7.9
- 0.7.8
- 0.7.7
- 0.7.6
This package is auto-updated.
Last update: 2024-09-07 03:38:35 UTC
README
将应用程序转换为强大的API。安装Gato GraphQL包将其转换为GraphQL服务器,并安装REST API包以启用添加REST端点。
安装
安装一个完全工作的API
遵循Bootstrap a PoP API for WordPress下的说明(尽管是CMS无关的,但目前仅实现了WordPress适配器)。
安装此库
通过Composer
composer require pop-api/api
启用漂亮永久链接
Apache
将以下代码添加到.htaccess
文件中,以启用API端点/api/
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / # Rewrite from /some-url/api/ to /some-url/?scheme=api RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^(.*)/api/?$ /$1/?scheme=api [L,P,QSA] # Rewrite from api/ to /?scheme=api RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^api/?$ /?scheme=api [L,P,QSA] </IfModule>
要添加扩展的漂亮API端点(GraphQL => /api/graphql/
),REST => /api/rest/
),将以下代码添加到.htaccess
文件中
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / # a. Resource endpoints # 1 and 2. GraphQL or REST: Rewrite from /some-url/api/(graphql|rest)/ to /some-url/?scheme=api&datastructure=(graphql|rest) RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^(.*)/api/(graphql|rest)/?$ /$1/?scheme=api&datastructure=$2 [L,P,QSA] # b. Homepage single endpoint (root) # 1 and 2. GraphQL or REST: Rewrite from api/(graphql|rest)/ to /?scheme=api&datastructure=(graphql|rest) RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^api/(graphql|rest)/?$ /?scheme=api&datastructure=$1 [L,P,QSA] </IfModule>
Nginx
将以下代码添加到Nginx配置的server
条目中,以启用API端点/api/
。请注意,下面的解析器是Docker的解析器;将此值替换为您的环境。
location ~ ^(.*)/api/?$ { # Resolver for Docker. Change to your own resolver 127.0.0.11 [::1]; # If adding $args and it's empty, it does a redirect from /api/ to ?scheme=api. # Then, add $args only if not empty set $redirect_uri "$scheme://$server_name$1/?scheme=api"; if ($args) { set $redirect_uri "$scheme://$server_name$1/?$args&scheme=api"; } proxy_pass $redirect_uri; }
要添加扩展的漂亮API端点(GraphQL => /api/graphql/
),REST => /api/rest/
),请添加以下代码
location ~ ^(.*)/api/(rest|graphql)/?$ { # Resolver for Docker. Change to your own resolver 127.0.0.11 [::1]; set $redirect_uri "$scheme://$server_name$1/?scheme=api&datastructure=$2"; if ($args) { set $redirect_uri "$scheme://$server_name$1/?$args&scheme=api&datastructure=$2"; } proxy_pass $redirect_uri; }
开发
源代码托管在GatoGraphQL monorepo中,在API/packages/api
下。
用法
初始化组件
\PoP\Root\App::stockAndInitializeModuleClasses([([ \PoPAPI\API\Module::class, ]);
PHP版本
要求
- 开发:PHP 8.1+
- 生产:PHP 7.2+
支持的PHP功能
请查看GatoGraphQL/GatoGraphQL中支持的PHP功能列表
预览降级到PHP 7.2
通过Rector(dry-run模式)
composer preview-code-downgrade
标准
通过PHP CodeSniffer检查编码标准,运行
composer check-style
自动修复问题,运行
composer fix-style
变更日志
有关最近更改的更多信息,请参阅CHANGELOG
测试
要执行PHPUnit,运行
composer test
静态分析
要执行PHPStan,运行
composer analyse
报告问题
要报告错误或请求新功能,请在GatoGraphQL monorepo问题跟踪器上操作。
贡献
我们欢迎在GatoGraphQL monorepo上对此包的贡献(其中包含此包的源代码)。
请参阅 CONTRIBUTING 和 CODE_OF_CONDUCT 了解详细信息。
安全
如果您发现任何与安全相关的问题,请通过电子邮件 leo@getpop.org 联系,而不是使用问题跟踪器。
鸣谢
许可证
GNU 通用公共许可证 v2(或更新版)。请参阅 许可证文件 获取更多信息。