-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
93 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 19 additions & 21 deletions
40
example/todo-list/src/pages/api-client/create-todo-client.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,36 @@ | ||
import { type APIRoute } from 'astro' | ||
import { type Todo } from '../../model/Todo' | ||
import { readFile, writeFile } from 'fs/promises' | ||
|
||
|
||
|
||
|
||
|
||
export interface QueryMap { | ||
[key: string]: string | ||
[key: string]: string | ||
} | ||
|
||
export interface RequestOptions extends RequestInit { | ||
query?: QueryMap | ||
query?: QueryMap | ||
} | ||
|
||
export interface ApiRequest extends Partial<Todo> {} | ||
export interface ApiRequest extends Partial<Todo> { } | ||
|
||
export interface ApiResponse { | ||
status: 'SUCCESS' | 'ERROR' | ||
error?: string | ||
todos: Array<Todo> | ||
status: 'SUCCESS' | 'ERROR' | ||
error?: string | ||
todos: Array<Todo> | ||
} | ||
|
||
|
||
/** return (await fetch('/api/create-todo', { method: 'POST', ... })).json() */ | ||
export const createTodo = async(payload: ApiRequest, options: RequestOptions = {}): Promise<ApiResponse> => { | ||
let requestUrl = 'http://localhost:4321/api/create-todo' | ||
if (options && options.query) { | ||
requestUrl += '?' + Object.keys(options.query) | ||
.map((key) => key + '=' + options.query![key]) | ||
.join('&'); | ||
} | ||
delete options.query | ||
options.method = 'POST' | ||
options.body = JSON.stringify(payload) | ||
return (await fetch(requestUrl, options)).json() | ||
} | ||
export const createTodo = async (payload: ApiRequest, options: RequestOptions = {}): Promise<ApiResponse> => { | ||
let requestUrl = 'http://localhost:4321/api/create-todo' | ||
if (options && options.query) { | ||
requestUrl += '?' + Object.keys(options.query) | ||
.map((key) => key + '=' + options.query![key]) | ||
.join('&'); | ||
} | ||
delete options.query | ||
options.method = 'POST' | ||
options.body = JSON.stringify(payload) | ||
return (await fetch(requestUrl, options)).json() | ||
} |
38 changes: 18 additions & 20 deletions
38
example/todo-list/src/pages/api-client/get-todos-client.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,36 @@ | ||
import { type APIRoute } from 'astro' | ||
import { type Todo } from '../../model/Todo' | ||
import { readFile } from 'fs/promises' | ||
|
||
|
||
|
||
|
||
|
||
export interface QueryMap { | ||
[key: string]: string | ||
[key: string]: string | ||
} | ||
|
||
export interface RequestOptions extends RequestInit { | ||
query?: QueryMap | ||
query?: QueryMap | ||
} | ||
|
||
|
||
|
||
export interface ApiResponse { | ||
status: 'SUCCESS' | 'ERROR' | ||
error?: string | ||
todos: Array<Todo> | ||
status: 'SUCCESS' | 'ERROR' | ||
error?: string | ||
todos: Array<Todo> | ||
} | ||
|
||
|
||
/** return (await fetch('/api/get-todos', { method: 'GET', ... })).json() */ | ||
export const getTodos = async(options: RequestOptions = {}): Promise<ApiResponse> => { | ||
let requestUrl = 'http://localhost:4321/api/get-todos' | ||
if (options && options.query) { | ||
requestUrl += '?' + Object.keys(options.query) | ||
.map((key) => key + '=' + options.query![key]) | ||
.join('&'); | ||
} | ||
delete options.query | ||
options.method = 'GET' | ||
return (await fetch(requestUrl, options)).json() | ||
} | ||
export const getTodos = async (options: RequestOptions = {}): Promise<ApiResponse> => { | ||
let requestUrl = 'http://localhost:4321/api/get-todos' | ||
if (options && options.query) { | ||
requestUrl += '?' + Object.keys(options.query) | ||
.map((key) => key + '=' + options.query![key]) | ||
.join('&'); | ||
} | ||
delete options.query | ||
options.method = 'GET' | ||
|
||
return (await fetch(requestUrl, options)).json() | ||
} |
40 changes: 19 additions & 21 deletions
40
example/todo-list/src/pages/api-client/remove-todo-client.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,38 @@ | ||
import { type APIContext, type APIRoute } from 'astro' | ||
import { type Todo } from '../../model/Todo' | ||
import { readFile, writeFile } from 'fs/promises' | ||
|
||
|
||
|
||
|
||
|
||
export interface QueryMap { | ||
[key: string]: string | ||
[key: string]: string | ||
} | ||
|
||
export interface RequestOptions extends RequestInit { | ||
query?: QueryMap | ||
query?: QueryMap | ||
} | ||
|
||
export interface ApiRequest { | ||
id: number | ||
id: number | ||
} | ||
|
||
export interface ApiResponse { | ||
status: 'SUCCESS' | 'ERROR' | ||
error?: string | ||
todos: Array<Todo> | ||
status: 'SUCCESS' | 'ERROR' | ||
error?: string | ||
todos: Array<Todo> | ||
} | ||
|
||
|
||
/** return (await fetch('/api/remove-todo', { method: 'DELETE', ... })).json() */ | ||
export const removeTodo = async(payload: ApiRequest, options: RequestOptions = {}): Promise<ApiResponse> => { | ||
let requestUrl = 'http://localhost:4321/api/remove-todo' | ||
if (options && options.query) { | ||
requestUrl += '?' + Object.keys(options.query) | ||
.map((key) => key + '=' + options.query![key]) | ||
.join('&'); | ||
} | ||
delete options.query | ||
options.method = 'DELETE' | ||
options.body = JSON.stringify(payload) | ||
return (await fetch(requestUrl, options)).json() | ||
} | ||
export const removeTodo = async (payload: ApiRequest, options: RequestOptions = {}): Promise<ApiResponse> => { | ||
let requestUrl = 'http://localhost:4321/api/remove-todo' | ||
if (options && options.query) { | ||
requestUrl += '?' + Object.keys(options.query) | ||
.map((key) => key + '=' + options.query![key]) | ||
.join('&'); | ||
} | ||
delete options.query | ||
options.method = 'DELETE' | ||
options.body = JSON.stringify(payload) | ||
return (await fetch(requestUrl, options)).json() | ||
} |
40 changes: 19 additions & 21 deletions
40
example/todo-list/src/pages/api-client/update-todo-client.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,36 @@ | ||
import { type APIContext, type APIRoute } from 'astro' | ||
import { type Todo } from '../../model/Todo' | ||
import { readFile, writeFile } from 'fs/promises' | ||
|
||
|
||
|
||
|
||
|
||
export interface QueryMap { | ||
[key: string]: string | ||
[key: string]: string | ||
} | ||
|
||
export interface RequestOptions extends RequestInit { | ||
query?: QueryMap | ||
query?: QueryMap | ||
} | ||
|
||
export interface ApiRequest extends Partial<Todo> {} | ||
export interface ApiRequest extends Partial<Todo> { } | ||
|
||
export interface ApiResponse { | ||
status: 'SUCCESS' | 'ERROR' | ||
error?: string | ||
todos: Array<Todo> | ||
status: 'SUCCESS' | 'ERROR' | ||
error?: string | ||
todos: Array<Todo> | ||
} | ||
|
||
|
||
/** return (await fetch('/api/update-todo', { method: 'PATCH', ... })).json() */ | ||
export const updateTodo = async(payload: ApiRequest, options: RequestOptions = {}): Promise<ApiResponse> => { | ||
let requestUrl = 'http://localhost:4321/api/update-todo' | ||
if (options && options.query) { | ||
requestUrl += '?' + Object.keys(options.query) | ||
.map((key) => key + '=' + options.query![key]) | ||
.join('&'); | ||
} | ||
delete options.query | ||
options.method = 'PATCH' | ||
options.body = JSON.stringify(payload) | ||
return (await fetch(requestUrl, options)).json() | ||
} | ||
export const updateTodo = async (payload: ApiRequest, options: RequestOptions = {}): Promise<ApiResponse> => { | ||
let requestUrl = 'http://localhost:4321/api/update-todo' | ||
if (options && options.query) { | ||
requestUrl += '?' + Object.keys(options.query) | ||
.map((key) => key + '=' + options.query![key]) | ||
.join('&'); | ||
} | ||
delete options.query | ||
options.method = 'PATCH' | ||
options.body = JSON.stringify(payload) | ||
return (await fetch(requestUrl, options)).json() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
[{"id":1,"task":"Implement the code generator","isDone":false},{"id":2,"task":"Reach 100% code coverage with Jest unit tests","isDone":false},{"id":3,"task":"Make some devs out there happy","isDone":false},{"id":4,"task":"Practice acceptance for when haters gonna hate :)","isDone":false}] | ||
[{"id":1,"task":"Implement the code generator","isDone":true},{"id":2,"task":"Reach 100% code coverage with Jest unit tests","isDone":true},{"id":3,"task":"Make some devs out there happy","isDone":true},{"id":4,"task":"Practice acceptance for when haters gonna hate :)","isDone":true},{"id":5,"task":"asd","isDone":false}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -475,10 +475,10 @@ | |
"@jridgewell/resolve-uri" "3.1.0" | ||
"@jridgewell/sourcemap-codec" "1.4.14" | ||
|
||
"@jsheaven/[email protected].0": | ||
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/@jsheaven/astro-client-generator/-/astro-client-generator-1.1.0.tgz#d27be4b1f6bb7672aa682a83f904f8f4f64b6409" | ||
integrity sha512-1ts+ZibGWz6Jme4R8Rq3hgJypUhwWotZY4DxFKr4T6tkJ8w99RShrhBnJK21mWKAyMJBuOKMf8Xfvk3LllZFhg== | ||
"@jsheaven/[email protected].1": | ||
version "1.1.1" | ||
resolved "https://registry.yarnpkg.com/@jsheaven/astro-client-generator/-/astro-client-generator-1.1.1.tgz#30da9b48c00fbd1cc2a70b51bdaff1be78eecd1c" | ||
integrity sha512-ChCYiOg/m2ZC0QEAxtzbPIEvMOShBiPqij7ERHJ1ED0J4jiHRj1/nLVouAI96zbXbf3fdB0d2WPKr5QH39uMZg== | ||
dependencies: | ||
kleur "^4.1.5" | ||
ts-morph "^21.0.1" | ||
|