Postman Requests Exercise

Understanding the Problem

We need to interact with a local server using Postman to perform several HTTP operations:

We'll be working with a server running on localhost:5000 that provides various endpoints for managing posts and comments.

Devising a Plan

  1. Start the local server using npm start
  2. Create a new post using POST /posts
  3. Verify post creation using GET /posts
  4. Add two comments using POST /posts/:postId/comments
  5. Verify comments using GET /posts/:postId
  6. Edit the post using POST /posts/:postId
  7. Delete one comment using POST /comments/:commentId/delete
  8. Verify final state using GET endpoints

Carrying Out the Plan

Step 1: Server Setup

# In terminal:
cd server
npm install
npm start
        

Step 2: Create New Post

Request:

Method: POST
URL: http://localhost:5000/posts
Headers: Content-Type: application/x-www-form-urlencoded
Body: 
    title: My First Post
    description: This is a test post
        

Step 3: Add Comments

Request (repeat twice with different text):

Method: POST
URL: http://localhost:5000/posts/1/comments
Headers: Content-Type: application/x-www-form-urlencoded
Body:
    text: This is comment 1
        

Step 4: Edit Post

Method: POST
URL: http://localhost:5000/posts/1
Headers: Content-Type: application/x-www-form-urlencoded
Body:
    title: Updated Post Title
    description: Updated post description
        

Step 5: Delete Comment

Method: POST
URL: http://localhost:5000/comments/1/delete
Headers: Content-Type: application/x-www-form-urlencoded
        

Looking Back & Real-World Applications

Understanding HTTP Methods

Think of HTTP methods like different types of interactions in a library:

Real-World Examples

These operations are similar to:

Common Pitfalls

Testing Tips

Extended Learning

To deepen your understanding, try: