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 fetch interceptors and custom parameters #84

Merged
merged 2 commits into from
Dec 7, 2024
Merged

Conversation

ReS4
Copy link

@ReS4 ReS4 commented Dec 6, 2024

This PR provides a set of custom attributes for fetch requests including request and response interceptors.

<script setup>
  const request = "http://vuefinder-php.test"
  
  // Or ...
  const request = {
    // ----- CHANGE ME! -----
    // [REQUIRED] Url for development server endpoint
    baseUrl: "http://vuefinder-php.test",
    // ----- CHANGE ME! -----

    // Additional headers & params & body
    headers: { "X-ADDITIONAL-HEADER": 'yes' },
    params: { additionalParam1: 'yes' },
    body: { additionalBody1: ['yes'] },

    // And/or transform request callback
    transformRequest: req => {
      if (req.method === 'get') {
        req.params.vf = "1"
      }
      return req;
    },

    // XSRF Token header name
    xsrfHeaderName: "X-CSRF-TOKEN",

    // Custom fetch parameters
    fetchParams: {
      'credentials': 'include',
      'mode': 'cors'
    },

    fetchRequestInterceptor: (req: any) => {
      console.log(req)
      return req;
    },

    fetchResponseInterceptor: async (response: any) => {
      console.log(response)
      return response;
    },
  }
</script>

@n1crack n1crack merged commit a6c5372 into n1crack:master Dec 7, 2024
@n1crack
Copy link
Owner

n1crack commented Dec 7, 2024

ty

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