diff --git a/README.md b/README.md index ae53591..77c592c 100644 --- a/README.md +++ b/README.md @@ -199,15 +199,11 @@ Once everything is set up to test API routes either use Postman or any other api ### Postman API example collection -You can import the example collection to Postman +You can import the example collection to Postman. To import, click the import button located and select `postman-setup.json` located within the root directory. - +Then create environments for dev, prod etc. Within each of the environments you create you will need to: -If you use Postman please go to `manage environments` and then create one for each of your servers (Ex. myApi-LOCAL, myApi-PRODUCTION). - -On each of the environments you create you will need to: - -1. Create a new key `authToken` with `token` value (the token you got from the login process), each time you make a request to the API it will send `Authorization` header with the token value in the request, you can check this on the headers of users or cities endpoints in the Postman example. +1. Create a new key `token` and within the `/login` request this value is automatically updated after a successfull login through a script located in the `tests` tab. Each time you make a request to the API it will send `Authorization` header with the `token` value in the request, you can check this on the headers of users or cities endpoints in the Postman example. 2. Create a second key `server` with the url of your server, for development mode use This is a REST API, so it works using the following HTTP methods: diff --git a/postman-setup.json b/postman-setup.json new file mode 100644 index 0000000..cf19822 --- /dev/null +++ b/postman-setup.json @@ -0,0 +1,883 @@ +{ + "info": { + "_postman_id": "fc28b46a-09b6-4fdc-b0e9-8cd70dde9329", + "name": "api node mongo jw", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "AUTH", + "item": [ + { + "name": "/register", + "request": { + "auth": { + "type": "noauth" + }, + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/x-www-form-urlencoded" + }, + { + "key": "Accept-Language", + "value": "en", + "type": "text" + } + ], + "body": { + "mode": "urlencoded", + "urlencoded": [ + { + "key": "name", + "value": "My Name", + "type": "text" + }, + { + "key": "email", + "value": "my@email.com", + "type": "text" + }, + { + "key": "password", + "value": "12345", + "type": "text" + } + ] + }, + "url": { + "raw": "{{server}}/register", + "host": [ + "{{server}}" + ], + "path": [ + "register" + ] + } + }, + "response": [] + }, + { + "name": "/verify", + "request": { + "auth": { + "type": "noauth" + }, + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/x-www-form-urlencoded" + } + ], + "body": { + "mode": "urlencoded", + "urlencoded": [ + { + "key": "id", + "value": "b98b1dea-b3f4-4b72-bcdf-9d36607e2603", + "type": "text" + } + ] + }, + "url": { + "raw": "{{server}}/verify", + "host": [ + "{{server}}" + ], + "path": [ + "verify" + ] + } + }, + "response": [] + }, + { + "name": "/forgot", + "request": { + "auth": { + "type": "noauth" + }, + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/x-www-form-urlencoded" + }, + { + "key": "Accept-Language", + "value": "en", + "type": "text" + } + ], + "body": { + "mode": "urlencoded", + "urlencoded": [ + { + "key": "email", + "value": "admin@admin.com", + "type": "text" + } + ] + }, + "url": { + "raw": "{{server}}/forgot", + "host": [ + "{{server}}" + ], + "path": [ + "forgot" + ] + } + }, + "response": [] + }, + { + "name": "/reset", + "request": { + "auth": { + "type": "noauth" + }, + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/x-www-form-urlencoded" + } + ], + "body": { + "mode": "urlencoded", + "urlencoded": [ + { + "key": "id", + "value": "f5b08991-02fc-4f3d-9a32-6d703bef5c57", + "type": "text" + }, + { + "key": "password", + "value": "12345", + "type": "text" + } + ] + }, + "url": { + "raw": "{{server}}/reset", + "host": [ + "{{server}}" + ], + "path": [ + "reset" + ] + } + }, + "response": [] + }, + { + "name": "/login", + "event": [ + { + "listen": "test", + "script": { + "id": "39d81ad8-c914-4af3-aec6-8699d3ecf23a", + "exec": [ + "//- auto populates token to environment variables", + "const jsonData = pm.response.json();", + "console.log(`JSON Response: ${jsonData}`);", + "const token = jsonData.token;", + "console.log(`Token: ${token}`);", + "", + "pm.environment.set('token', token);", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "auth": { + "type": "noauth" + }, + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/x-www-form-urlencoded" + } + ], + "body": { + "mode": "urlencoded", + "urlencoded": [ + { + "key": "email", + "value": "admin@admin.com", + "type": "text" + }, + { + "key": "password", + "value": "12345", + "type": "text" + } + ] + }, + "url": { + "raw": "{{server}}/login", + "host": [ + "{{server}}" + ], + "path": [ + "login" + ] + } + }, + "response": [] + }, + { + "name": "/token", + "request": { + "method": "GET", + "header": [ + { + "key": "Authorization", + "value": "Bearer {{token}}" + } + ], + "url": { + "raw": "{{server}}/token", + "host": [ + "{{server}}" + ], + "path": [ + "token" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "USERS", + "item": [ + { + "name": "/users", + "request": { + "method": "GET", + "header": [ + { + "key": "Authorization", + "value": "Bearer {{token}}" + } + ], + "url": { + "raw": "{{server}}/users?filter=ad&fields=name,email&page=1&limit=10&sort=name&order=-1", + "host": [ + "{{server}}" + ], + "path": [ + "users" + ], + "query": [ + { + "key": "filter", + "value": "ad" + }, + { + "key": "fields", + "value": "name,email" + }, + { + "key": "page", + "value": "1" + }, + { + "key": "limit", + "value": "10" + }, + { + "key": "sort", + "value": "name" + }, + { + "key": "order", + "value": "-1" + } + ] + } + }, + "response": [] + }, + { + "name": "/users", + "request": { + "method": "POST", + "header": [ + { + "key": "Authorization", + "value": "Bearer {{token}}" + }, + { + "key": "Content-Type", + "value": "application/x-www-form-urlencoded" + } + ], + "body": { + "mode": "urlencoded", + "urlencoded": [ + { + "key": "name", + "value": "New User", + "type": "text" + }, + { + "key": "email", + "value": "myemail@email.com", + "type": "text" + }, + { + "key": "password", + "value": "12345", + "type": "text" + }, + { + "key": "role", + "value": "admin", + "type": "text" + }, + { + "key": "phone", + "value": "123123", + "type": "text" + }, + { + "key": "city", + "value": "Bucaramamga", + "type": "text" + }, + { + "key": "country", + "value": "Colombia", + "type": "text" + } + ] + }, + "url": { + "raw": "{{server}}/users", + "host": [ + "{{server}}" + ], + "path": [ + "users" + ] + } + }, + "response": [] + }, + { + "name": "/users/:id", + "request": { + "method": "DELETE", + "header": [ + { + "key": "Authorization", + "value": "Bearer {{token}}" + } + ], + "body": { + "mode": "formdata", + "formdata": [] + }, + "url": { + "raw": "{{server}}/users/5aab2443ef417d2d19e6c8f2", + "host": [ + "{{server}}" + ], + "path": [ + "users", + "5aab2443ef417d2d19e6c8f2" + ] + } + }, + "response": [] + }, + { + "name": "/users/:id", + "request": { + "method": "GET", + "header": [ + { + "key": "Authorization", + "value": "Bearer {{token}}" + } + ], + "url": { + "raw": "{{server}}/users/5aa1c2c35ef7a4e97b5e995a", + "host": [ + "{{server}}" + ], + "path": [ + "users", + "5aa1c2c35ef7a4e97b5e995a" + ] + } + }, + "response": [] + }, + { + "name": "/users/:id", + "request": { + "method": "PATCH", + "header": [ + { + "key": "Authorization", + "value": "Bearer {{token}}" + }, + { + "key": "Content-Type", + "value": "application/x-www-form-urlencoded" + } + ], + "body": { + "mode": "urlencoded", + "urlencoded": [ + { + "key": "name", + "value": "New Name", + "type": "text" + }, + { + "key": "email", + "value": "new@email.com", + "type": "text" + }, + { + "key": "role", + "value": "admin", + "type": "text" + }, + { + "key": "phone", + "value": "12345", + "type": "text" + }, + { + "key": "city", + "value": "Cali", + "type": "text" + }, + { + "key": "country", + "value": "Colombia", + "type": "text" + } + ] + }, + "url": { + "raw": "http://localhost:3000/users/5aa1c2c35ef7a4e97b5e995a?", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "3000", + "path": [ + "users", + "5aa1c2c35ef7a4e97b5e995a" + ], + "query": [ + { + "key": "sort", + "value": "id ASC", + "disabled": true + }, + { + "key": "skip", + "value": "3", + "disabled": true + }, + { + "key": "where", + "value": "{ 'email' : { startsWith : 'f' } }", + "disabled": true + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "PROFILE", + "item": [ + { + "name": "/profile", + "request": { + "method": "GET", + "header": [ + { + "key": "Authorization", + "value": "Bearer {{token}}" + } + ], + "url": { + "raw": "{{server}}/profile", + "host": [ + "{{server}}" + ], + "path": [ + "profile" + ] + } + }, + "response": [] + }, + { + "name": "/profile", + "request": { + "method": "PATCH", + "header": [ + { + "key": "Authorization", + "value": "Bearer {{token}}" + }, + { + "key": "Content-Type", + "value": "application/x-www-form-urlencoded" + } + ], + "body": { + "mode": "urlencoded", + "urlencoded": [ + { + "key": "name", + "value": "My Name", + "type": "text" + }, + { + "key": "urlTwitter", + "value": "https://hello.com", + "type": "text" + }, + { + "key": "urlGitHub", + "value": "https://hello.io", + "type": "text" + }, + { + "key": "phone", + "value": "444444", + "type": "text" + }, + { + "key": "city", + "value": "Boston2", + "type": "text" + }, + { + "key": "country", + "value": "Colombia2", + "type": "text" + } + ] + }, + "url": { + "raw": "{{server}}/profile", + "host": [ + "{{server}}" + ], + "path": [ + "profile" + ] + } + }, + "response": [] + }, + { + "name": "/profile/changePassword", + "request": { + "method": "POST", + "header": [ + { + "key": "Authorization", + "value": "Bearer {{token}}" + }, + { + "key": "Content-Type", + "value": "application/x-www-form-urlencoded" + } + ], + "body": { + "mode": "urlencoded", + "urlencoded": [ + { + "key": "oldPassword", + "value": "12345", + "type": "text" + }, + { + "key": "newPassword", + "value": "12345", + "type": "text" + } + ] + }, + "url": { + "raw": "{{server}}/profile/changePassword", + "host": [ + "{{server}}" + ], + "path": [ + "profile", + "changePassword" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "CITIES", + "item": [ + { + "name": "/cities/all", + "request": { + "method": "GET", + "header": [ + { + "key": "Authorization", + "value": "Bearer {{token}}" + } + ], + "url": { + "raw": "{{server}}/cities/all", + "host": [ + "{{server}}" + ], + "path": [ + "cities", + "all" + ] + } + }, + "response": [] + }, + { + "name": "/cities", + "request": { + "method": "GET", + "header": [ + { + "key": "Authorization", + "value": "Bearer {{token}}" + } + ], + "url": { + "raw": "{{server}}/cities?filter=Bucaramanga&fields=name&page=1&limit=5&sort=name&order=1", + "host": [ + "{{server}}" + ], + "path": [ + "cities" + ], + "query": [ + { + "key": "filter", + "value": "Bucaramanga" + }, + { + "key": "fields", + "value": "name" + }, + { + "key": "page", + "value": "1" + }, + { + "key": "limit", + "value": "5" + }, + { + "key": "sort", + "value": "name" + }, + { + "key": "order", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "/cities", + "request": { + "method": "POST", + "header": [ + { + "key": "Authorization", + "value": "Bearer {{token}}" + }, + { + "key": "Content-Type", + "value": "application/x-www-form-urlencoded" + } + ], + "body": { + "mode": "urlencoded", + "urlencoded": [ + { + "key": "name", + "value": "Miami", + "type": "text" + } + ] + }, + "url": { + "raw": "{{server}}/cities", + "host": [ + "{{server}}" + ], + "path": [ + "cities" + ] + } + }, + "response": [] + }, + { + "name": "/cities/:id", + "request": { + "method": "GET", + "header": [ + { + "key": "Authorization", + "value": "Bearer {{token}}" + }, + { + "key": "Accept-Language", + "value": "es", + "type": "text" + } + ], + "url": { + "raw": "{{server}}/cities/5bd08db979bbc504c14ebfdd", + "host": [ + "{{server}}" + ], + "path": [ + "cities", + "5bd08db979bbc504c14ebfdd" + ] + } + }, + "response": [] + }, + { + "name": "/cities/:id", + "request": { + "method": "PATCH", + "header": [ + { + "key": "Authorization", + "value": "Bearer {{token}}" + }, + { + "key": "Content-Type", + "value": "application/x-www-form-urlencoded" + } + ], + "body": { + "mode": "urlencoded", + "urlencoded": [ + { + "key": "name", + "value": "Seatle2", + "type": "text" + } + ] + }, + "url": { + "raw": "{{server}}/cities/5bd08db979bbc504c14ebfdd?", + "host": [ + "{{server}}" + ], + "path": [ + "cities", + "5bd08db979bbc504c14ebfdd" + ], + "query": [ + { + "key": "sort", + "value": "id ASC", + "disabled": true + }, + { + "key": "skip", + "value": "3", + "disabled": true + }, + { + "key": "where", + "value": "{ 'email' : { startsWith : 'f' } }", + "disabled": true + } + ] + } + }, + "response": [] + }, + { + "name": "/cities/:id", + "request": { + "method": "DELETE", + "header": [ + { + "key": "Authorization", + "value": "Bearer {{token}}" + } + ], + "body": { + "mode": "formdata", + "formdata": [] + }, + "url": { + "raw": "{{server}}/cities/5b38171b1843d58427c5d6c4", + "host": [ + "{{server}}" + ], + "path": [ + "cities", + "5b38171b1843d58427c5d6c4" + ] + } + }, + "response": [] + } + ] + } + ], + "event": [ + { + "listen": "prerequest", + "script": { + "id": "ac527f82-7509-47cb-8599-33b9ed4df0e2", + "type": "text/javascript", + "exec": [ + "" + ] + } + }, + { + "listen": "test", + "script": { + "id": "e3a9aa02-e160-40a7-ac06-9b06e99a991b", + "type": "text/javascript", + "exec": [ + "" + ] + } + } + ] +} \ No newline at end of file