Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Laravel HTTP Client macros to consume JSON:API documents #2

Merged
merged 1 commit into from
Feb 22, 2022

Conversation

JaZo
Copy link
Member

@JaZo JaZo commented Feb 22, 2022

Description

I've added JSON:API macros to the Laravel HTTP Client.

use Illuminate\Support\Facades\Http;
use Swis\JsonApi\Client\Facades\DocumentFactoryFacade;
use Swis\JsonApi\Client\Item;

$recipe = (new Item())
    ->setType('recipes')
    ->fill([
        'title' => 'Frankfurter salad with mustard dressing',
    ]);

$document = Http::asJsonApi() // Sets the Content-Type and Accept headers to 'application/vnd.api+json'.
    ->post('https://cms.contentacms.io/api/recipes', DocumentFactoryFacade::make($recipe))
    ->jsonApi(); // Parses the response into a JSON:API document.

Motivation and context

This makes it easy to work with JSON:API documents using the Http facade.

How has this been tested?

Copied from a project where I've used these macros.

Types of changes

What types of changes does your code introduce? Put an x in all the boxes that apply:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

Go over all the following points, and put an x in all the boxes that apply.

  • I have read the CONTRIBUTING document.
  • My pull request addresses exactly one patch/feature.
  • I have created a branch for this patch/feature.
  • Each individual commit in the pull request is meaningful.
  • I have added tests to cover my changes.
  • If my change requires a change to the documentation, I have updated it accordingly.

@JaZo JaZo force-pushed the feature/http-client-macros branch from 6427b37 to b240e42 Compare February 22, 2022 09:05
@bbrala
Copy link
Member

bbrala commented Feb 22, 2022

Looks good :)

@JaZo JaZo merged commit c701207 into master Feb 22, 2022
@JaZo JaZo deleted the feature/http-client-macros branch February 22, 2022 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants