Bird
0
0

Which of the following is the correct syntax to send a POST request with JSON body using Cypress API-first setup?

easy📝 Syntax Q3 of 15
Cypress - Test Organization and Patterns
Which of the following is the correct syntax to send a POST request with JSON body using Cypress API-first setup?
Acy.request('POST', '/api/items')
Bcy.request('POST', '/api/items', {name: 'book', price: 10})
Ccy.request('GET', '/api/items', {name: 'book', price: 10})
Dcy.request('/api/items', {name: 'book', price: 10})
Step-by-Step Solution
Solution:
  1. Step 1: Check correct method and parameters for POST request

    cy.request() takes method, URL, and body as parameters. cy.request('POST', '/api/items', {name: 'book', price: 10}) correctly uses 'POST', URL, and JSON body.
  2. Step 2: Identify errors in other options

    cy.request('/api/items', {name: 'book', price: 10}) misses method, defaults to GET; cy.request('GET', '/api/items', {name: 'book', price: 10}) uses GET with body (invalid); cy.request('POST', '/api/items') misses body for POST.
  3. Final Answer:

    cy.request('POST', '/api/items', {name: 'book', price: 10}) -> Option B
  4. Quick Check:

    POST request syntax = cy.request('POST', '/api/items', {name: 'book', price: 10}) [OK]
Quick Trick: POST requests need method, URL, and body in cy.request() [OK]
Common Mistakes:
  • Omitting HTTP method defaults to GET
  • Sending body with GET request
  • Forgetting to include body in POST request

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes