Giter VIP home page Giter VIP logo

Comments (2)

mikaeljorhult avatar mikaeljorhult commented on June 2, 2024 1

Thank you @Sammyjo20! I didn't know about these HTTP methods either just last week. =) Very much an edge case though as they seem to be more or less specific to WebDAV.

Your solution is working great. I did try similar ideas but managed to miss handlePsrRequest. Thank you again and have a great week!

from saloon.

Sammyjo20 avatar Sammyjo20 commented on June 2, 2024

Hey @mikaeljorhult

I have never heard of these HTTP methods before! 😅 The HTTP method is an enum so I think it would be difficult to extend it... That being said you may be able to hack it slightly by writing a PSR handler in your connector. For example

Your connector

You could add a method called handlePsrRequest and change the HTTP method from a method you can add from your request class.

<?php

namespace App\Http\Integrations\Test;

use Psr\Http\Message\RequestInterface;
use Saloon\Http\Connector;
use Saloon\Http\PendingRequest;
use Saloon\Traits\Plugins\AcceptsJson;

class TestConnector extends Connector
{
    use AcceptsJson;

    /**
     * The Base URL of the API
     */
    public function resolveBaseUrl(): string
    {
        return 'https://tests.saloon.dev/api';
    }

    /**
     * Default headers for every request
     */
    protected function defaultHeaders(): array
    {
        return [];
    }

    /**
     * Default HTTP client options
     */
    protected function defaultConfig(): array
    {
        return [];
    }

    public function handlePsrRequest(RequestInterface $request, PendingRequest $pendingRequest): RequestInterface
    {
        return $request->withMethod($pendingRequest->getRequest()->getNativeMethod());
    }
}

Your request

You would add the getNativeMethod on your request like this

<?php

namespace App\Http\Integrations\Test\Requests;

use GuzzleHttp\RequestOptions;
use Saloon\Enums\Method;
use Saloon\Http\Request;

class UserRequest extends Request
{
    /**
     * The HTTP method of the request
     */
    protected Method $method = Method::GET;

    /**
     * The endpoint for the request
     */
    public function resolveEndpoint(): string
    {
        return '/user';
    }

    public function getNativeMethod(): string
    {
        return 'PROPFIND';
    }
}

With this way, you would be overwriting the protected Method $method property on your request, so this could be anything.

from saloon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.