Introducing Postman, a tool for testing REST API

Postman is a wonderful tool that allows Windows, macOS X, and Linux users to make HTTP API requests. You can download it at https://www.getpostman.com/.

After installing Postman, enter a URL in the Enter request URL input text. Select the type of request (GET, POST, and so on). For each request, we can have many settings such as headers, POST body, and other details. Please go through the Postman documentation for more details. The basic usage of Postman is straightforward. Take a look at the following screenshot:

The builder is the window where we can add/edit requests. The preceding screenshot shows the empty builder where we try to make requests. Run the main.go in the preceding simpleAuth project and try to call the health check API, like this. Click on the Send button and you will see the response is forbidden:

This is because we didn't log in yet. Postman automatically saves the cookie once authentication is successful. Now, call the login API by changing the method type from GET to POST and URL to http://localhost:8000/login. We should also pass the auth details as multipart form data. It looks like the following screenshot:

Now, if we hit send, it authenticates and receives the cookie. It returns a message saying Logged In successfully. We can also inspect the cookies by clicking on the Cookies link just below the Send and Save buttons on right-hand side. It shows the list of cookies saved and you will find a cookie called session.id there for localhost. The content will look like this:

session.id=MTUwODYzNDcwN3xEdi1CQkFFQ180SUFBUkFCRUFBQUpmLUNBQUVHYzNSeWFXNW5EQThBRFdGMWRHaGxiblJwWTJGMFpXUUVZbTl2YkFJQ0FBRT189iF-ruBQmyTdtAOaMR-Rr9lNtsf1OJgirBDkcBpdEa0=; path=/; domain=localhost; Expires=Tue Nov 21 2017 01:11:47 GMT+0530 (IST);

Try to call the health check API again, and it returns us the system date and time:

2017-10-22 06:54:36.464214959 +0530 IST

If a client makes a GET request to the logout API:

http://localhost:8000/logout

The session will be invalidated and access to the resource will be forbidden until another login request is done.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.151.44