MCPcopy
hub / github.com/codeceptjs/CodeceptJS / makeApiRequest

Method makeApiRequest

lib/helper/Playwright.js:3052–3081  ·  view source on GitHub ↗

* Performs [api request](https://playwright.dev/docs/api/class-apirequestcontext#api-request-context-get) using * the cookies from the current browser session. * * ```js * const users = await I.makeApiRequest('GET', '/api/users', { params: { page: 1 }}); * users[0] * I.makeApiReque

(method, url, options)

Source from the content-addressed store, hash-verified

3050 * @returns {Promise<object>} response
3051 */
3052 async makeApiRequest(method, url, options) {
3053 method = method.toLowerCase()
3054 const allowedMethods = ['get', 'post', 'patch', 'head', 'fetch', 'delete']
3055 if (!allowedMethods.includes(method)) {
3056 throw new Error(`Method ${method} is not allowed, use the one from a list ${allowedMethods} or switch to using REST helper`)
3057 }
3058
3059 if (url.startsWith('/')) {
3060 // local url
3061 url = this.options.url + url
3062 this.debugSection('URL', url)
3063 }
3064
3065 const response = await this.page.request[method](url, options)
3066 this.debugSection('Status', response.status())
3067 this.debugSection('Response', await response.text())
3068
3069 // hook to allow JSON response handle this
3070 if (this.options.onResponse) {
3071 const axiosResponse = {
3072 data: await response.json(),
3073 status: response.status(),
3074 statusText: response.statusText(),
3075 headers: response.headers(),
3076 }
3077 this.options.onResponse(axiosResponse)
3078 }
3079
3080 return response
3081 }
3082
3083 async _failed(test) {
3084 await this._withinEnd()

Callers 4

Playwright_test.jsFile · 0.80
config_test.jsFile · 0.80

Calls 1

includesMethod · 0.80

Tested by

no test coverage detected