ZTTP will be in Laravel 7 | What is ZTTP and How to use it ?

Updated 21 January 2021

What is ZTTP ?

Zttp is a simple Guzzle wrapper designed to provide a really pleasant development experience for most common use cases. It is a new PHP package by Adam Wathan that is a Guzzle wrapper designed to bring an expressive syntax and simplify common use cases.

It provides a much nicer syntax for the use case of Guzzle where you just need to POST some JSON to an endpoint.
let’s find out the basic usage of this new http package.

Is it official ?

Well, yes it is an authenticated news coming directly from Taylor Otwell.
He merged the request on github and mentioned:

This is a port of Adam Wathan’s ZTTP Guzzle convenience layer. It provides much nicer syntax for the 90% use case of Guzzle where you just need to POST some JSON to an endpoint. In addition, this supplements ZTTP with stubbing / faking inspired by jason mccreary’s work on that library.

This is not an entirely new client – it is only a UX / DX convenience layer on top of Guzzle. We will not be adding a lot of complicated features to this. If you need very, very robust or complicated logic just use Guzzle directly. We aren’t trying to expose every feature of Guzzle through this API.

How to use it ? (Basic usage)

Headers/Authentication

With the help of Zttp, headers can be added using the withHeaders method.

Authorization

Along with that, you can now also use basic authentication.

Errors

By default, like ZTTP, exceptions are not thrown on client and server errors. If you receive a response that is not successful and you would like to throw an exception, you may call $response->throw().

Post with form parameters

Patch Request

Put Request

Delete Request

Sources: 
Laravel News
PR on GitHub

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home