Skip to content

Commit 2cc6d83

Browse files
chore: add get character of api
1 parent b6b5d8e commit 2cc6d83

File tree

6 files changed

+118
-10
lines changed

6 files changed

+118
-10
lines changed

api-swagger.yaml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,110 @@ paths:
2121
$ref: '#/definitions/get-health-200'
2222
'404':
2323
description: Error.
24+
'/character':
25+
get:
26+
tags:
27+
- Character
28+
summary: Get character of api Rick and Morty
29+
consumes:
30+
- application/json
31+
produces:
32+
- application/json
33+
parameters:
34+
- name: name
35+
type: string
36+
in: query
37+
required: false
38+
- name: status
39+
type: string
40+
in: query
41+
required: false
42+
enum:
43+
- Alive
44+
- Dead
45+
- unknown
46+
- name: species
47+
type: string
48+
in: query
49+
required: false
50+
- name: type
51+
type: string
52+
in: query
53+
required: false
54+
- name: gender
55+
type: string
56+
in: query
57+
required: false
58+
enum:
59+
- female
60+
- male
61+
- genderless
62+
- unknown
63+
responses:
64+
'200':
65+
description: Consulta satisfactoria
66+
schema:
67+
$ref: '#/definitions/get-character-200'
68+
'404':
69+
description: Error.
2470
definitions:
2571
get-health-200:
2672
type: object
2773
properties:
2874
status:
2975
type: string
76+
get-character-200:
77+
type: object
78+
properties:
79+
info:
80+
type: object
81+
properties:
82+
count:
83+
type: number
84+
pages:
85+
type: number
86+
next:
87+
type: string
88+
prev:
89+
type: string
90+
results:
91+
type: array
92+
items:
93+
type: object
94+
properties:
95+
id:
96+
type: number
97+
name:
98+
type: string
99+
status:
100+
type: string
101+
species:
102+
type: string
103+
type:
104+
type: string
105+
gender:
106+
type: string
107+
origin:
108+
type: object
109+
properties:
110+
name:
111+
type: string
112+
url:
113+
type: string
114+
location:
115+
type: object
116+
properties:
117+
name:
118+
type: string
119+
url:
120+
type: string
121+
image:
122+
type: string
123+
episode:
124+
type: array
125+
items:
126+
type: string
127+
url:
128+
type: string
129+
created:
130+
type: string

config/custom-environment-variables.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
"params": {
1919
},
2020
"services": {
21+
"apiRick": "API_RICK_URL"
2122
}
2223
}

config/development.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
"params": {
1919
},
2020
"services": {
21+
"apiRick": "https://rickandmortyapi.com/api"
2122
}
2223
}

config/test.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
"params": {
1919
},
2020
"services": {
21+
"apiRick": "https://rickandmortyapi.com/api"
2122
}
2223
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@
4646
},
4747
"prettier": {
4848
"semi": true,
49-
"singleQuote": true,
5049
"tabWidth": 2,
51-
"printWidth": 80,
50+
"singleQuote": true,
51+
"printWidth": 100,
5252
"trailingComma": "all"
5353
},
5454
"lint-staged": {

src/routes/character.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,28 @@ import { toStringify } from '../utils/converters';
55

66
module.exports = (app: Application, appConfig: any) => {
77
const { context } = appConfig['server'];
8+
const { apiRick } = appConfig['services'];
89

910
app.get(
1011
encodeURI(`${context}/character`),
1112
async (req: Request, res: Response): Promise<any> => {
1213
try {
13-
const params = { name: 'rick', status: 'alive', page: 2 };
14+
const params = { ...req.query };
1415

15-
const { status, data } = await httpClient.get(
16-
'https://rickandmortyapi.com/api/character/',
17-
{
18-
params,
19-
},
20-
);
16+
const urlService = encodeURI(`${apiRick}/character/`);
17+
const { status, data } = await httpClient.get(urlService, {
18+
params,
19+
});
20+
21+
signale.success({
22+
prefix: '[character] RESPONSE BODY',
23+
message: toStringify(data),
24+
});
2125

2226
res.status(status).send(data);
2327
} catch (error) {
2428
signale.error({
25-
prefix: '[spa-config] ERROR',
29+
prefix: '[character] ERROR',
2630
message: toStringify(error),
2731
});
2832
res

0 commit comments

Comments
 (0)