18.1: Test with Swagger

Test the Login with Swagger

In this section, we test our endpoints with swagger. You may be wondering why we need to do this after already having used Postman. The big difference is that Swagger is embedded into your application, and thus is exclusive to it. Postman, on the other hand, is a third party tool in which you can test multiple applications in the same collection.

  1. Run the app

  2. Add /swagger to the end of your URL

  3. Click on Auth and then Expand Operations

    Auth

  4. For the grant_type, type 'password'

  5. Enter in your username and password and click Try it out!

  6. You should receive a token for that user in the Response Body

  7. Copy the token without the quotes

    Token

Test GET Notes with Swagger

  1. Click on Note and then the GET method

  2. In the Authorization field, type Bearer then a space, and then paste the token

    Paste Token

  3. Click Try It Out! and you should see all of the notes for the logged in user in the Response Body

    Notes

Test POST Note with Swagger

  1. Click List Operations to minimize the GET notes endpoint

  2. Click on the POST endpoint

  3. Click in the box w/ JSON and it will copy the text over to the box on the left

    JSON Copy

  4. In the box on the left, replace string with a title for your note and the other string with the content

  5. Copy and paste the Bearer token from the previous endpoint test

  6. Click Try it Out! and make sure it works

Test GET Note with Swagger

  1. Go to the GET /api/Note/{id} request

  2. Type in the NoteId of the note you just posted, you can find it in dbo.Note if you're unsure.

  3. Paste the Bearer token

  4. Click Try it Out! and make sure it works

  5. Copy the JSON received by the GET request, the Response Body section.

    JSON

Test PUT to Edit a Note

  1. Paste the JSON from the GET into the PUT request

  2. Remove the Created and Modified entries

  3. Modify the Title and/or Content

  4. Paste the Bearer token and click Try it Out!

  5. Re-run either GET method to make sure the note has changed.

Test DELETE

  1. Go to the DELETE request

  2. Type in a NoteId and paste the Bearer token.

  3. Click Try it Out!

  4. Re-run the first GET method that gets all the notes and make sure the deleted note is not there.

TaDa! You've finished ElevenNote!

Last updated