Skip to content

Commit 514f7d4

Browse files
feat: update how to define an endpoint in the docs
1 parent 170a413 commit 514f7d4

File tree

1 file changed

+84
-74
lines changed

1 file changed

+84
-74
lines changed

apps/meteor/app/api/README.md

Lines changed: 84 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -39,53 +39,63 @@ import Ajv from 'ajv';
3939

4040
const ajv = new Ajv();
4141

42-
API.v1
43-
.get(
44-
'endpoint-name',
45-
{
46-
authRequired: true,
47-
query: ajv.compile({
48-
type: 'object',
49-
properties: {
50-
param1: { type: 'string' },
51-
param2: { type: 'number' },
42+
API.v1.get(
43+
'endpoint-name',
44+
{
45+
authRequired: true,
46+
query: ajv.compile<{
47+
param1: string;
48+
param2: number;
49+
}>({
50+
type: 'object',
51+
properties: {
52+
param1: { type: 'string' },
53+
param2: { type: 'number' },
54+
},
55+
required: ['param1'],
56+
}),
57+
body: ajv.compile<{
58+
field1: string;
59+
field2: boolean;
60+
}>({
61+
type: 'object',
62+
properties: {
63+
field1: { type: 'string' },
64+
field2: { type: 'boolean' },
65+
},
66+
required: ['field1'],
67+
}),
68+
response: {
69+
200: ajv.compile<{
70+
count: number;
71+
offset: number;
72+
total: number;
73+
items: { _id: string; prop1: number; prop2: string; prop3: string }[];
74+
}>({
75+
additionalProperties: false,
76+
type: 'object',
77+
properties: {
78+
count: {
79+
type: 'number',
80+
description: 'The number of sounds returned in this response.',
5281
},
53-
required: ['param1'],
54-
}),
55-
body: ajv.compile({
56-
type: 'object',
57-
properties: {
58-
field1: { type: 'string' },
59-
field2: { type: 'boolean' },
82+
offset: {
83+
type: 'number',
84+
description: 'The number of sounds that were skipped in this response.',
6085
},
61-
required: ['field1'],
62-
}),
63-
response: {
64-
200: ajv.compile({
65-
additionalProperties: false,
66-
type: 'object',
67-
properties: {
68-
count: {
69-
type: 'number',
70-
description: 'The number of sounds returned in this response.',
71-
},
72-
offset: {
73-
type: 'number',
74-
description: 'The number of sounds that were skipped in this response.',
75-
},
76-
total: {
77-
type: 'number',
78-
description: 'The total number of sounds that match the query.',
79-
},
80-
success: {
81-
type: 'boolean',
82-
description: 'Indicates if the request was successful.',
83-
},
86+
total: {
87+
type: 'number',
88+
description: 'The total number of sounds that match the query.',
89+
},
90+
success: {
91+
type: 'boolean',
92+
description: 'Indicates if the request was successful.',
93+
},
94+
items: {
95+
type: 'array',
8496
items: {
85-
type: 'array',
86-
items: {
87-
type: 'object',
88-
properties: {
97+
type: 'object',
98+
properties: {
8999
_id: {
90100
type: 'string',
91101
},
@@ -100,40 +110,40 @@ API.v1
100110
},
101111
},
102112
required: ['_id', 'prop1', 'prop2', 'prop3'],
103-
},
104113
},
105114
},
106-
}),
107-
401: ajv.compile({
108-
additionalProperties: false,
109-
type: 'object',
110-
properties: {
111-
error: {
112-
type: 'string',
113-
},
114-
status: {
115-
type: 'string',
116-
nullable: true,
117-
},
118-
message: {
119-
type: 'string',
120-
nullable: true,
121-
},
122-
success: {
123-
type: 'boolean',
124-
description: 'Indicates if the request was successful.',
125-
},
115+
},
116+
}),
117+
401: ajv.compile({
118+
additionalProperties: false,
119+
type: 'object',
120+
properties: {
121+
error: {
122+
type: 'string',
126123
},
127-
required: ['success', 'error'],
128-
}),
129-
},
124+
status: {
125+
type: 'string',
126+
nullable: true,
127+
},
128+
message: {
129+
type: 'string',
130+
nullable: true,
131+
},
132+
success: {
133+
type: 'boolean',
134+
description: 'Indicates if the request was successful.',
135+
},
136+
},
137+
required: ['success', 'error'],
138+
}),
130139
},
140+
},
131141

132-
async function action() {
133-
const result = await anyLogic();
134-
return API.v1.success(result);
135-
},
136-
)
142+
async function action() {
143+
const result = await anyLogic();
144+
return API.v1.success(result);
145+
},
146+
);
137147
```
138148

139-
By following these guidelines, you ensure that your API endpoints are well-documented, validated, and maintainable.
149+
By following these guidelines, you ensure that your API endpoints are well-documented, validated, and maintainable.

0 commit comments

Comments
 (0)