Notes Postman
Notes Postman
Notes Postman
On the past to have access to some services inside an app our user had to share
its password with that app.
With OAuth we share our password with a OAuth server and the server
sends a token to the service to access the customer requiared data.
Postman
Is an API client. Lets us develop, test, document and share APIs. We can send
HTTP requests to APIs using Postman.
To our request we can add parameters that can filter our searches.
When we communicate with APIs we do not usually give our usernames and
password but instead we use tokens that sometimes give us limited access to
our accounts.
We can have scripts that can test the responses to our requests.
Pre-request Scripts are Javascript rutines that are run before our request
are sent.
Once we have Newman, to run our requests we can first import the collection
that have them, then from a terminal go to where the collection was imported
1
and then run the command
newman run name of the imported collection.
Another option is from Postman generate a link for your collection and use
the run command of Postman with that link to access the collection.
To get help relating the run command you can execute the command
newman run -h
Using JSON file to pass data to Postman to use this feature we have
to set an enviroment in our request then create a JSON file with the data we
want to pass. Finally use the option to run the collection and import the JSON
file with your data.
To pass a file from a terminal we use newman run collection name -d data
source location
Lambok
Is a Java library that reduce code by offering annotations that creates that code
for us.
Java Records
classes that contain data not meant to be altered and only the most funda-
mental methods such as constructors and accessors.
A public read accessor method for each component with the same name
and type of the component.
2
A public constructor whose signature is derived from the record compo-
nents list. The constructor initializes each private field from the corre-
sponding argument.
Implementations of the equals() and hashCode() methods, which specify
that two records are equal if they are of the same type and their corre-
sponding record components are equal.
An implementation of the toString() method that includes the string rep-
resentation of all the record’s components, with their names.
3
@Operation(summary = ”controller description”) can be used to an-
notate controller method and display a message describing the method’s roll in
the documentation generated by swagger. Example below
4
What is the difference between @ApiOperation and Operation?
OpenAPI Specification 3.0 OAS 3.0 SwaggerHub? API design and doc-
umentation platform.
Creating API Definition with SwaggerHub
1 openapi : 3.0.0
2 info :
3 version : 2.0.0
4 title : SmartBear HR API
5 description : Employees manager
6 terms OfServi ce : https :// smartbear . com / terms - of - use
7 contact :
8 name : Jeyson
9 url : smartbear . com
10 email : keshav . v a s u d e v a n @ s m a r t b e a r . com
11 license :
12 name : SmartBear License
13 url : hrrp :// license . foo . com
14
15 servers :
16 - url : https :// dev . foo . com / v1
5
17 description : Dev Server
18
19 - url : https :// prod . foo . com / v1
20 description : Prod Server
21
22 paths :
23 / employees :
24 get :
25 description : Get information about employees from the HR
database
26 parameters :
27 - name : bodyLimit
28 in : query
29 description : The amount of employees returned
30 schema :
31 type : integer
32 minimum : 10
33 maximum : 20
34 example : 15
35
36 - name : pageLimit
37 in : query
38 description : The pages to return employees info
39 schema :
40 type : integer
41 minimum : 1
42 maximum : 5
43 example : 2
44
45 responses :
46 200:
47 description : Successful pull of employee info
48 content :
49 application / json :
50 schema :
51 type : array
52 items :
53 $ ref : ’#/ components / schemas / Employees ’
54 post :
55 description : Creates a new employee in the database
56 requestBody :
57 required : true
58 content :
59 application / json :
60 schema :
61 type : object
62 $ ref : ’#/ components / schemas / Employee ’
63
64 responses :
65 200:
66 description : Succesfully created a new employee
67
68 / employees /{ id }:
69 get :
70 description : Given an id obtain information of the employee
with that id .
71 parameters :
72 - in : path
73 name : id
74 required : true
75 description : The ID of the employee
76 schema :
6
77 type : integer
78 example : 54
79
80 responses :
81 200:
82 description : Success
83 content :
84 application / json :
85 schema :
86 type : object
87 $ ref : ’#/ components / schemas / Employee ’
88 application / xml :
89 schema :
90 type : object
91 $ ref : ’#/ components / schemas / Employee ’
92 components :
93 schemas :
94 Employees :
95 description : Array of employees information
96 type : array
97 items :
98 $ ref : ’#/ components / schemas / Employee ’
99
100
101 Employee :
102 description : Model containing employee information
103 properties :
104 id :
105 type : integer
106 example : 4
107
108 employee name :
109 type : string
110 example : John Doe
111
112 employee title :
113 type : string
114 example : Software developer