Skip to content

Commit eb313cc

Browse files
committed
remove express js
1 parent 79eeeea commit eb313cc

21 files changed

+458
-445
lines changed

README.md

Lines changed: 184 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,132 @@
1-
# tech-report-apis
1+
# Technology Reports API (Node.js)
22

3-
APIs for the HTTP Archive Technology Report
3+
This is a unified Google Cloud Run function that provides technology metrics and information via various endpoints.
44

5-
## API
5+
## Setup
66

7-
## Endpoints
7+
### Prerequisites
88

9-
### `GET /adoption`
9+
- Node.js 18+
10+
- npm
11+
- Google Cloud account with necessary permissions
12+
- Set environment variables:
13+
14+
```bash
15+
export PROJECT=httparchive
16+
export DATABASE=tech-report-apis-prod
17+
```
18+
19+
### Local Development
20+
21+
```bash
22+
npm install
23+
npm start:functions
24+
```
25+
26+
The API will be available at <http://localhost:8080>
27+
28+
### Google Cloud Functions Mode
29+
30+
```bash
31+
npm install
32+
npm run start:functions
33+
```
34+
35+
The function will run on `http://localhost:8080`
36+
37+
## Deployment
38+
39+
### Deploy to Google Cloud Run Function
40+
41+
```bash
42+
# Deploy to Google Cloud Functions
43+
gcloud functions deploy tech-report-api \
44+
--runtime nodejs22 \
45+
--trigger-http \
46+
--allow-unauthenticated \
47+
--entry-point api \
48+
--source .
49+
```
50+
51+
## API Endpoints
52+
53+
## Features
54+
55+
- **ETag Support**: All endpoints include ETag headers for efficient caching
56+
- **CORS Enabled**: Cross-origin requests are supported
57+
- **Cache Headers**: 6-hour cache control for static data
58+
- **Health Check**: GET `/` returns health status
59+
- **RESTful API**: All endpoints follow REST conventions
60+
61+
### `GET /`
62+
63+
Health check
64+
65+
### `GET /technologies`
66+
67+
Lists available technologies with optional filtering.
1068

1169
#### Parameters
1270

13-
The following parameters can be used to filter the data:
71+
- `technology` (optional): Filter by technology name(s) - comma-separated list
72+
- `category` (optional): Filter by category - comma-separated list
73+
- `onlyname` (optional): If present, returns only technology names
74+
75+
#### Example Request & Response
76+
77+
```bash
78+
curl --request GET \
79+
--url 'https://{{HOST}}/v1/technologies?category=Live%20chat%2C%20blog&technology=Smartsupp'
80+
```
1481

15-
- `geo` (`required`): A string representing the geographic location.
16-
- `technology` (`required`): A comma-separated string representing the technology name(s).
17-
- `rank` (`required`): An string representing the rank.
18-
- `start` (optional): A string representing the start date in the format `YYYY-MM-DD`.
19-
- `end` (optional): A string representing the end date in the format `YYYY-MM-DD`.
82+
Returns a JSON object with the following schema:
2083

21-
#### Response
84+
```json
85+
[
86+
{
87+
"technology": "Smartsupp",
88+
"category": "Live chat",
89+
"description": "Smartsupp is a live chat tool that offers visitor recording feature.",
90+
"icon": "Smartsupp.svg",
91+
"origins": {
92+
"mobile": 24115,
93+
"desktop": 20250
94+
}
95+
}
96+
]
97+
```
2298

2399
```bash
24100
curl --request GET \
25-
--url 'https://{{HOST}}/v1/adoption?start=2023-01-01&end=2023-09-01&geo=Mexico&technology=GoCache&rank=ALL'
101+
--url 'https://{{HOST}}/v1/technologies?onlyname'
26102
```
27103

28104
Returns a JSON object with the following schema:
29105

30106
```json
31107
[
32-
{
33-
"technology": "GoCache",
34-
"geo": "Mexico",
35-
"date": "2023-06-01",
36-
"rank": "ALL",
37-
"adoption": {
38-
"mobile": 19,
39-
"desktop": 11
40-
}
41-
},
108+
"1C-Bitrix",
109+
"2B Advice",
110+
"33Across",
111+
"34SP.com",
112+
"4-Tell",
113+
"42stores",
114+
"51.LA",
115+
"5centsCDN",
42116
...
43-
]
117+
}
44118
```
45119
46120
### `GET /categories`
47121
48-
This endpoint can return a full list of categories names or a categories with all the associated technologies
49-
50-
#### Parameters
122+
Lists available categories.
51123
52-
The following parameters can be used to filter the data:
124+
#### Categories Parameters
53125
54-
- `category` (optional): A comma-separated string representing the category name(s).
55-
- `onlyname` (optional): No value required. If present, only the category names will be returned.
126+
- `category` (optional): Filter by category name(s) - comma-separated list
127+
- `onlyname` (optional): If present, returns only category names
56128
57-
#### Response
129+
#### Categories Response
58130
59131
```bash
60132
curl --request GET \
@@ -105,22 +177,58 @@ curl --request GET \
105177
"Analytics",
106178
...
107179
]
180+
```
181+
182+
### `GET /adoption`
183+
184+
Provides technology adoption data.
185+
186+
#### Adoption Parameters
108187
188+
- `technology` (required): Filter by technology name(s) - comma-separated list
189+
- `start` (optional): Filter by date range start (YYYY-MM-DD or 'latest')
190+
- `end` (optional): Filter by date range end (YYYY-MM-DD)
191+
- `geo` (optional): Filter by geographic location
192+
- `rank` (optional): Filter by rank
193+
194+
#### Adoption Response
195+
196+
```bash
197+
curl --request GET \
198+
--url 'https://{{HOST}}/v1/adoption?start=2023-01-01&end=2023-09-01&geo=Mexico&technology=GoCache&rank=ALL'
109199
```
110200
111-
### `GET /cwv`
201+
Returns a JSON object with the following schema:
112202
113-
#### Parameters
203+
```json
204+
[
205+
{
206+
"technology": "GoCache",
207+
"geo": "Mexico",
208+
"date": "2023-06-01",
209+
"rank": "ALL",
210+
"adoption": {
211+
"mobile": 19,
212+
"desktop": 11
213+
}
214+
},
215+
...
216+
]
217+
```
218+
219+
### `GET /cwv` (Core Web Vitals)
220+
221+
Provides Core Web Vitals metrics for technologies.
114222
115-
The following parameters can be used to filter the data:
223+
#### CWV Parameters
116224
117-
- `geo` (`required`): A string representing the geographic location.
118-
- `technology` (`required`): A string representing the technology name.
119-
- `rank` (`required`): An string representing the rank.
120-
- `start` (optional): A string representing the start date in the format `YYYY-MM-DD`.
121-
- `end` (optional): A string representing the end date in the format `YYYY-MM-DD`.
225+
- `technology` (required): Filter by technology name(s) - comma-separated list
226+
- `geo` (required): Filter by geographic location
227+
- `rank` (required): Filter by rank
228+
- `start` (optional): Filter by date range start (YYYY-MM-DD or 'latest')
229+
- `end` (optional): Filter by date range end (YYYY-MM-DD)
122230
123-
#### Response
231+
#### CWV Response
124232
125233
```bash
126234
curl --request GET \
@@ -151,22 +259,21 @@ curl --request GET \
151259
]
152260
}
153261
]
154-
155262
```
156263
157264
### `GET /lighthouse`
158265
159-
#### Parameters
266+
Provides Lighthouse scores for technologies.
160267
161-
The following parameters can be used to filter the data:
268+
#### Lighthouse Parameters
162269
163-
- `technology` (`required`): A comma-separated string representing the technology name(s).
164-
- `geo` (`required`): A string representing the geographic location.
165-
- `rank` (`required`): An string representing the rank.
166-
- `start` (optional): A string representing the start date in the format `YYYY-MM-DD`.
167-
- `end` (optional): A string representing the end date in the format `YYYY-MM-DD`.
270+
- `technology` (required): Filter by technology name(s) - comma-separated list
271+
- `geo` (required): Filter by geographic location
272+
- `rank` (required): Filter by rank
273+
- `start` (optional): Filter by date range start (YYYY-MM-DD or 'latest')
274+
- `end` (optional): Filter by date range end (YYYY-MM-DD)
168275
169-
#### Response
276+
#### Lighthouse Response
170277
171278
```bash
172279
curl --request GET \
@@ -205,17 +312,17 @@ Returns a JSON object with the following schema:
205312
206313
### `GET /page-weight`
207314
208-
#### Parameters
315+
Provides Page Weight metrics for technologies.
209316
210-
The following parameters can be used to filter the data:
317+
#### Page Weight Parameters
211318
212-
- `geo` (`required`): A string representing the geographic location.
213-
- `technology` (`required`): A comma-separated string representing the technology name(s).
214-
- `rank` (`required`): An string representing the rank.
215-
- `start` (optional): A string representing the start date in the format `YYYY-MM-DD`.
216-
- `end` (optional): A string representing the end date in the format `YYYY-MM-DD`.
319+
- `technology` (required): Filter by technology name(s) - comma-separated list
320+
- `geo` (optional): Filter by geographic location
321+
- `rank` (optional): Filter by rank
322+
- `start` (optional): Filter by date range start (YYYY-MM-DD or 'latest')
323+
- `end` (optional): Filter by date range end (YYYY-MM-DD)
217324
218-
#### Response
325+
#### Page Weight Response
219326
220327
```bash
221328
curl --request GET \
@@ -240,57 +347,41 @@ Returns a JSON object with the following schema:
240347
]
241348
```
242349
243-
### `GET /technologies`
350+
### `GET /ranks`
244351
245-
#### Parameters
352+
Lists all available ranks.
246353
247-
The following parameters can be used to filter the data:
354+
### `GET /geos`
248355
249-
- `technology` (optional): A comma-separated string representing the technology name(s) or `ALL`.
250-
- `category` (optional): A comma-separated string representing the category name(s).
251-
- `onlyname` (optional): No value required. If present, only the technology names will be returned.
356+
Lists all available geographic locations.
252357
253-
#### Response
358+
## Testing
254359
255360
```bash
256-
curl --request GET \
257-
--url 'https://{{HOST}}/v1/technologies?category=Live%20chat%2C%20blog&technology=Smartsupp'
361+
# Run all tests
362+
npm test
363+
364+
# Run tests with coverage
365+
npm run test
258366
```
259367
260-
Returns a JSON object with the following schema:
368+
## Response Format
369+
370+
All API responses follow this format:
261371
262372
```json
263373
[
264-
{
265-
"technology": "Smartsupp",
266-
"category": "Live chat",
267-
"description": "Smartsupp is a live chat tool that offers visitor recording feature.",
268-
"icon": "Smartsupp.svg",
269-
"origins": {
270-
"mobile": 24115,
271-
"desktop": 20250
272-
}
273-
}
374+
// Array of data objects
274375
]
275376
```
276377
277-
```bash
278-
curl --request GET \
279-
--url 'https://{{HOST}}/v1/technologies?onlyname'
280-
```
281-
282-
Returns a JSON object with the following schema:
378+
Or in case of an error:
283379
284380
```json
285-
[
286-
"1C-Bitrix",
287-
"2B Advice",
288-
"33Across",
289-
"34SP.com",
290-
"4-Tell",
291-
"42stores",
292-
"51.LA",
293-
"5centsCDN",
294-
...
381+
{
382+
"success": false,
383+
"errors": [
384+
{"key": "error message"}
385+
]
295386
}
296387
```

0 commit comments

Comments
 (0)