├── .gitignore ├── README.md └── Contact API.postman_collection.json /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | node_modules 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ILT Cloud 2 Bangkit Demo 2 | 3 | ## Simple RESTFul API 4 | 5 | Create the simple RESTFul API using Node.js Natively and Hapi Framework with the specification: 6 | 7 | | Method | Path | Response Code | Body | Description | 8 | | ------ |---------------| ------------- | ---- |---------------------| 9 | | POST | /contacts | 201 | JSON | Create new contacts | 10 | | GET | /contacts | 200 | JSON | List of contacts | 11 | | DELETE | /contacts/:id | 200 | JSON | Delete contacts | 12 | 13 | User data structure: 14 | 15 | ```json 16 | { 17 | "id": "1", 18 | "name": "John Doe", 19 | "email": "john@example.com", 20 | "phone": "1234567890" 21 | } 22 | ``` 23 | Server options: 24 | - `port`: 3000 25 | - `host`: localhost 26 | 27 | 28 | -------------------------------------------------------------------------------- /Contact API.postman_collection.json: -------------------------------------------------------------------------------- 1 | { 2 | "info": { 3 | "_postman_id": "3780cdcc-3651-4269-96e5-a291ddaabd07", 4 | "name": "Contact API", 5 | "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" 6 | }, 7 | "item": [ 8 | { 9 | "name": "Add Contact", 10 | "event": [ 11 | { 12 | "listen": "test", 13 | "script": { 14 | "exec": [ 15 | "pm.test('it should response with 201 status code', () => {", 16 | " pm.response.to.have.status(201);", 17 | "});", 18 | "", 19 | "pm.test('Content-Type header should contain application/json', () => {", 20 | " pm.expect(pm.response.headers.get('Content-Type')).to.include('application/json');", 21 | "});", 22 | "" 23 | ], 24 | "type": "text/javascript" 25 | } 26 | } 27 | ], 28 | "request": { 29 | "method": "POST", 30 | "header": [], 31 | "body": { 32 | "mode": "raw", 33 | "raw": "{\n \"name\": \"Jane Doe\",\n \"email\": \"jane@axample.com\",\n \"phone\": \"1234567890\"\n}", 34 | "options": { 35 | "raw": { 36 | "language": "json" 37 | } 38 | } 39 | }, 40 | "url": { 41 | "raw": "localhost:3000/contacts", 42 | "host": [ 43 | "localhost" 44 | ], 45 | "port": "3000", 46 | "path": [ 47 | "contacts" 48 | ] 49 | } 50 | }, 51 | "response": [] 52 | }, 53 | { 54 | "name": "Get Contacts", 55 | "event": [ 56 | { 57 | "listen": "test", 58 | "script": { 59 | "exec": [ 60 | "pm.test('it should response with 200 status code', () => {", 61 | " pm.response.to.have.status(200);", 62 | "});", 63 | "", 64 | "pm.test('Content-Type header should contain application/json', () => {", 65 | " pm.expect(pm.response.headers.get('Content-Type')).to.include('application/json');", 66 | "});", 67 | "", 68 | "pm.test('response body should contain at least 1 contact', () => {", 69 | " const contacts = pm.response.json();", 70 | " ", 71 | " pm.expect(contacts).to.have.length.at.least(1);", 72 | "});", 73 | "" 74 | ], 75 | "type": "text/javascript" 76 | } 77 | } 78 | ], 79 | "request": { 80 | "method": "GET", 81 | "header": [], 82 | "url": { 83 | "raw": "localhost:3000/contacts", 84 | "host": [ 85 | "localhost" 86 | ], 87 | "port": "3000", 88 | "path": [ 89 | "contacts" 90 | ] 91 | } 92 | }, 93 | "response": [] 94 | }, 95 | { 96 | "name": "Delete Contact by Id", 97 | "event": [ 98 | { 99 | "listen": "test", 100 | "script": { 101 | "exec": [ 102 | "pm.test('it should response with 200 status code', () => {", 103 | " pm.response.to.have.status(200);", 104 | "});", 105 | "", 106 | "pm.test('Content-Type header should contain application/json', () => {", 107 | " pm.expect(pm.response.headers.get('Content-Type')).to.include('application/json');", 108 | "});", 109 | "" 110 | ], 111 | "type": "text/javascript" 112 | } 113 | } 114 | ], 115 | "request": { 116 | "method": "DELETE", 117 | "header": [], 118 | "url": { 119 | "raw": "localhost:3000/contacts/2", 120 | "host": [ 121 | "localhost" 122 | ], 123 | "port": "3000", 124 | "path": [ 125 | "contacts", 126 | "2" 127 | ] 128 | } 129 | }, 130 | "response": [] 131 | } 132 | ] 133 | } --------------------------------------------------------------------------------