# 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](https://3258533034-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfMZK4G04fkoGGv%2F-LAxsf-FSfJUGuXOU3f_%2F-LAxsgdJHn26t9vMiya4%2F18.1-A.png?generation=1524677924132199\&alt=media)
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](https://3258533034-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfMZK4G04fkoGGv%2F-LAxsf-FSfJUGuXOU3f_%2F-LAxsgerNkZw7SF35Mo6%2F18.1-B.png?generation=1524677927481607\&alt=media)

## 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](https://3258533034-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfMZK4G04fkoGGv%2F-LAxsf-FSfJUGuXOU3f_%2F-LAxsggsQIxD5BppEbQh%2F18.1-C.png?generation=1524677927075118\&alt=media)
3.  Click **Try It Out!** and you should see all of the notes for the logged in user in the **Response Body**

    ![Notes](https://3258533034-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfMZK4G04fkoGGv%2F-LAxsf-FSfJUGuXOU3f_%2F-LAxsghjaMi34z8rkaH3%2F18.1-D.png?generation=1524677928117644\&alt=media)

## 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](https://3258533034-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfMZK4G04fkoGGv%2F-LAxsf-FSfJUGuXOU3f_%2F-LAxsgkN7YqzRpWJeZwu%2F18.1-E.png?generation=1524677929217138\&alt=media)
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](https://3258533034-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfMZK4G04fkoGGv%2F-LAxsf-FSfJUGuXOU3f_%2F-LAxsgqgc-N3dtcqs23J%2F18.1-JSON.PNG?generation=1524677928420460\&alt=media)

## 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!](https://media.giphy.com/media/26FmSeF5yosvEgWNq/giphy.gif) You've finished ElevenNote!
