-
Notifications
You must be signed in to change notification settings - Fork 24
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
17 changed files
with
377 additions
and
538 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
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
42 changes: 21 additions & 21 deletions
42
AspNetCoreExample.Generator/output/api/WeatherForecastApi.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,41 +1,41 @@ | ||
// tslint:disable | ||
// TypeScriptContractGenerator's generated content | ||
import { WeatherForecast } from './../DataTypes/WeatherForecast'; | ||
import { Guid } from './../DataTypes/Guid'; | ||
import { ApiBase } from './../ApiBase/ApiBase'; | ||
import { url } from './../ApiBase/ApiBase'; | ||
|
||
export class WeatherForecastApi extends ApiBase implements IWeatherForecastApi { | ||
async get(): Promise<WeatherForecast[]> { | ||
return this.makeGetRequest(`/WeatherForecast`, { | ||
|
||
}, { | ||
|
||
}); | ||
get(): Promise<WeatherForecast[]> { | ||
return this.makeGetRequest(url`/WeatherForecast`); | ||
} | ||
|
||
async update(city: string, forecast: WeatherForecast): Promise<void> { | ||
return this.makePostRequest(`/WeatherForecast/Update/${city}`, { | ||
|
||
}, { | ||
...forecast, | ||
}); | ||
update(city: string, forecast: WeatherForecast): Promise<void> { | ||
return this.makePostRequest(url`/WeatherForecast/Update/${city}`, forecast); | ||
} | ||
|
||
async reset(seed: number): Promise<void> { | ||
return this.makePostRequest(`/Reset`, { | ||
['seed']: seed, | ||
}, { | ||
|
||
}); | ||
reset(seed: number): Promise<void> { | ||
return this.makePostRequest(url`/Reset?seed=${seed}`); | ||
} | ||
|
||
getDownloadUrl(city: string): string { | ||
return `/WeatherForecast/${city}`; | ||
urlForDownload(city: string): string { | ||
return url`/WeatherForecast/${city}`; | ||
} | ||
|
||
urlForGetStreetView(street: string, useGoogleImages: boolean): string { | ||
return url`/WeatherForecast/${street}/view?useGoogleImages=${useGoogleImages}`; | ||
} | ||
|
||
newGuid(): Promise<Guid> { | ||
return this.makeGetRequest(url`/WeatherForecast/none`); | ||
} | ||
|
||
}; | ||
export interface IWeatherForecastApi { | ||
get(): Promise<WeatherForecast[]>; | ||
update(city: string, forecast: WeatherForecast): Promise<void>; | ||
reset(seed: number): Promise<void>; | ||
getDownloadUrl(city: string): string; | ||
urlForDownload(city: string): string; | ||
urlForGetStreetView(street: string, useGoogleImages: boolean): string; | ||
newGuid(): Promise<Guid>; | ||
} |
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,58 +1,45 @@ | ||
/* eslint-disable */ | ||
|
||
interface IParamsMap { | ||
[key: string]: null | undefined | number | string | any[] | boolean; | ||
} | ||
export const url = String.raw; | ||
|
||
export class ApiBase { | ||
public async makeGetRequest(url: string, queryParams: IParamsMap, body: any): Promise<any> { | ||
const response = await fetch(this.getUrl(url, queryParams), { | ||
public async makeGetRequest(url: string, body?: any): Promise<any> { | ||
const response = await fetch(url, { | ||
method: "GET", | ||
}); | ||
return await response.json(); | ||
} | ||
|
||
public async makePostRequest(url: string, queryParams: IParamsMap, body: any): Promise<any> { | ||
const response = await fetch(this.getUrl(url, queryParams), { | ||
public async makePostRequest(url: string, body?: any): Promise<any> { | ||
const response = await fetch(url, { | ||
method: "POST", | ||
body: JSON.stringify(body), | ||
body: body && JSON.stringify(body), | ||
}); | ||
const textResult = await response.text(); | ||
if (textResult !== "") { | ||
return JSON.parse(textResult); | ||
} | ||
} | ||
|
||
public async makePutRequest(url: string, queryParams: IParamsMap, body: any): Promise<any> { | ||
const response = await fetch(this.getUrl(url, queryParams), { | ||
public async makePutRequest(url: string, body?: any): Promise<any> { | ||
const response = await fetch(url, { | ||
method: "PUT", | ||
body: JSON.stringify(body), | ||
body: body && JSON.stringify(body), | ||
}); | ||
const textResult = await response.text(); | ||
if (textResult !== "") { | ||
return JSON.parse(textResult); | ||
} | ||
} | ||
|
||
public async makeDeleteRequest(url: string, queryParams: IParamsMap, body: any): Promise<any> { | ||
const response = await fetch(this.getUrl(url, queryParams), { | ||
public async makeDeleteRequest(url: string, body?: any): Promise<any> { | ||
const response = await fetch(url, { | ||
method: "DELETE", | ||
body: JSON.stringify(body), | ||
body: body && JSON.stringify(body), | ||
}); | ||
const textResult = await response.text(); | ||
if (textResult !== "") { | ||
return JSON.parse(textResult); | ||
} | ||
} | ||
|
||
public getUrl(url: string, params?: IParamsMap): string { | ||
return url + this.createQueryString(params); | ||
} | ||
|
||
public createQueryString(params: any): string { | ||
if (params == null) { | ||
return ""; | ||
} | ||
return `${new URLSearchParams(params)}`; | ||
} | ||
} |
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
Oops, something went wrong.