-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotes
More file actions
90 lines (72 loc) · 3.03 KB
/
notes
File metadata and controls
90 lines (72 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
======================================
REST API BASICS – QUICK NOTES
======================================
What is REST?
-------------
- REST (Representational State Transfer) is an architectural style for building web services.
- RESTful APIs use HTTP as the communication protocol.
- Key principles:
* Stateless communication
* Resource-based (identified by URIs)
* Uses standard HTTP methods
* Supports multiple formats (commonly JSON, XML)
--------------------------------------
Common HTTP Methods
--------------------------------------
GET - Retrieve data from a resource (e.g., Get user details)
POST - Create a new resource (e.g., Create a new user)
PUT - Update/replace an existing resource (e.g., Update user info completely)
PATCH - Partially update an existing resource (e.g., Update user’s email only)
DELETE - Remove a resource (e.g., Delete a user)
HEAD - Similar to GET, but only headers (e.g., Check if resource exists)
OPTIONS - Describes allowed HTTP methods (e.g., Discover API capabilities)
--------------------------------------
HTTP Status Codes
--------------------------------------
1xx – Informational
100 Continue – Request headers OK, continue with body
2xx – Success
200 OK – Successful request
201 Created – Resource created successfully
204 No Content – Success but no response body
3xx – Redirection
301 Moved Permanently – Resource moved
302 Found – Temporary redirect
304 Not Modified – Resource not changed since last request
4xx – Client Errors
400 Bad Request – Invalid request
401 Unauthorised – Authentication required/failed
403 Forbidden – Authenticated but not authorised
404 Not Found – Resource not found
409 Conflict – Resource conflict (e.g., duplicate data)
5xx – Server Errors
500 Internal Server Error – Unexpected server failure
502 Bad Gateway – Invalid response from upstream server
503 Service Unavailable – Server temporarily down
504 Gateway Timeout – Upstream server did not respond in time
--------------------------------------
Best Practices for REST APIs
--------------------------------------
- Use nouns in URIs, not verbs → /users/123 instead of /getUser
- Support filtering, sorting, and pagination → /users?page=2&limit=50
- Use plural nouns for resources → /orders, /products
- Implement proper status codes for clarity
- Document APIs using OpenAPI/Swagger
- Secure APIs with HTTPS, authentication, and rate limiting
================
Newman CLI
================
1. Run a Collection
newman run collection.json
2. Run with Environment
newman run collection.json -e environment.json
3. Run with Data File (CSV/JSON)
newman run collection.json -d data.csv
4. Run with Reporters (CLI, HTML, JSON, JUnit)
newman run collection.json -reporters cli,html,json
5. Save HTML Report to Custom Folder
newman run collection.json -r html --reporter-html-export reports/report.html
6. Set Iterations
newman run collection.json -n 5
7. Run in CI/CD (exit with code on failure)
newman run collection.json --suppress-exit-code