• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

laravel-json-api/laravel: JSON:API for Laravel applications

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

laravel-json-api/laravel

开源软件地址(OpenSource Url):

https://github.com/laravel-json-api/laravel

开源编程语言(OpenSource Language):

PHP 100.0%

开源软件介绍(OpenSource Introduction):

Tests

JSON:API for Web Artisans

Implement feature-rich JSON:API compliant APIs in your Laravel applications. Build your next standards-compliant API today.

Why use JSON:API and Laravel JSON:API?

Great question! Here's some reasons from this excellent article by Denisa Halmaghi:

Why Use JSON:API?

  • Standardised, consistent APIs.
  • Feature rich - some of which are: sparse fieldsets (only fetch the fields you need), filtering, sorting, pagination, eager loading for relationships (includes, which solve the N+1 problem).
  • Easy to understand.

Why use Laravel JSON:API?

  • Saves a lot of development time.
  • Highly maintainable code.
  • Great, extensive documentation.
  • Strong conventions, but also highly customisable.
  • Makes use of native Laravel features such as policies and form requests to make the shift easier for developers.
  • Beautiful, expressive Nova-style schemas.
  • Fully testable via expressive test helpers.
class PostSchema extends Schema
{

    /**
     * The model the schema corresponds to.
     *
     * @var string
     */
    public static string $model = Post::class;

    /**
     * The maximum include path depth.
     *
     * @var int
     */
    protected int $maxDepth = 3;

    /**
     * Get the resource fields.
     *
     * @return array
     */
    public function fields(): array
    {
        return [
            ID::make(),
            BelongsTo::make('author')->type('users')->readOnly(),
            HasMany::make('comments')->readOnly(),
            Str::make('content'),
            DateTime::make('createdAt')->sortable()->readOnly(),
            DateTime::make('publishedAt')->sortable(),
            Str::make('slug'),
            BelongsToMany::make('tags'),
            Str::make('title')->sortable(),
            DateTime::make('updatedAt')->sortable()->readOnly(),
        ];
    }

    /**
     * Get the resource filters.
     *
     * @return array
     */
    public function filters(): array
    {
        return [
            WhereIdIn::make($this),
            WhereIn::make('author', 'author_id'),
        ];
    }

    /**
     * Get the resource paginator.
     *
     * @return Paginator|null
     */
    public function pagination(): ?Paginator
    {
        return PagePagination::make();
    }
}

Documentation

See our website, laraveljsonapi.io

Tutorial

New to JSON:API and/or Laravel JSON:API? Then the Laravel JSON:API tutorial is a great way to learn!

Follow the tutorial to build a blog application with a JSON:API compliant API.

Installation

Install using Composer

composer require laravel-json-api/laravel

See our documentation for further installation instructions.

Upgrading

When upgrading you typically want to upgrade this package and all our related packages. This is the recommended way:

composer require laravel-json-api/laravel --no-update
composer require laravel-json-api/testing --dev --no-update
composer up "laravel-json-api/*" cloudcreativity/json-api-testing

Example Application

To view an example Laravel application that uses this package, see the Tutorial Application.

License

Laravel JSON:API is open-sourced software licensed under the Apache 2.0 License.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
antonioribeiro/health: Laravel Health Panel发布时间:2022-07-07
下一篇:
laravel/laravel.com: The source code of the official Laravel website.发布时间:2022-07-08
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap