Comparing version 0.6.2 to 0.7.0
@@ -5,2 +5,9 @@ # Changelog | ||
## [0.7.0](https://github.com/aspidajs/aspida/compare/v0.6.1...v0.7.0) (2019-11-23) | ||
### Features | ||
* **cli:** delete baseurl option ([9fc0bf3](https://github.com/aspidajs/aspida/commit/9fc0bf36c657a78175369422d7b6814855a87ab7)) | ||
### [0.6.2](https://github.com/aspidajs/aspida/compare/v0.6.1...v0.6.2) (2019-11-01) | ||
@@ -7,0 +14,0 @@ |
@@ -16,4 +16,4 @@ "use strict"; | ||
var options = { | ||
string: ['version', 'config', 'build', 'watch', 'baseurl'], | ||
alias: { v: 'version', c: 'config', b: 'build', w: 'watch', u: 'baseurl' } | ||
string: ['version', 'config', 'build', 'watch'], | ||
alias: { v: 'version', c: 'config', b: 'build', w: 'watch' } | ||
}; | ||
@@ -35,3 +35,3 @@ var getBuildCommandFactory = function (config) { | ||
argv.build !== undefined || argv.watch !== undefined | ||
? getBuildCommandFactory(getConfig_1.default(argv.config)).create(argv.watch !== undefined ? new build_1.Watch(argv.baseurl) : new build_1.Build(argv.baseurl)) | ||
? getBuildCommandFactory(getConfig_1.default(argv.config)).create(argv.watch !== undefined ? new build_1.Watch() : new build_1.Build()) | ||
: command_1.nullCommand | ||
@@ -38,0 +38,0 @@ ]; |
@@ -24,10 +24,7 @@ import { Config } from '../getConfig'; | ||
export declare class Build implements BuildCommand { | ||
private readonly baseUrl; | ||
constructor(baseUrl: string); | ||
run(input: string, io: BuildIO): void; | ||
} | ||
export declare class Watch implements BuildCommand { | ||
private readonly baseUrl; | ||
private readonly build; | ||
constructor(baseUrl: string, build?: Build); | ||
constructor(build?: Build); | ||
run(input: string, io: BuildIO): void; | ||
@@ -34,0 +31,0 @@ } |
@@ -31,8 +31,6 @@ "use strict"; | ||
var Build = /** @class */ (function () { | ||
// eslint-disable-next-line no-useless-constructor | ||
function Build(baseUrl) { | ||
this.baseUrl = baseUrl; | ||
function Build() { | ||
} | ||
Build.prototype.run = function (input, io) { | ||
var template = buildTemplate_1.default(input, this.baseUrl); | ||
var template = buildTemplate_1.default(input); | ||
io.write(template); | ||
@@ -45,12 +43,10 @@ }; | ||
// eslint-disable-next-line no-useless-constructor | ||
function Watch(baseUrl, build) { | ||
if (build === void 0) { build = new Build(baseUrl); } | ||
this.baseUrl = baseUrl; | ||
function Watch(build) { | ||
if (build === void 0) { build = new Build(); } | ||
this.build = build; | ||
} | ||
Watch.prototype.run = function (input, io) { | ||
var _this = this; | ||
this.build.run(input, io); | ||
io.watch(input, function () { | ||
var result = buildTemplate_1.default(input, _this.baseUrl); | ||
var result = buildTemplate_1.default(input); | ||
io.remove(result.filePath, function () { return io.write(result); }); | ||
@@ -57,0 +53,0 @@ }); |
{ | ||
"name": "aspida", | ||
"version": "0.6.2", | ||
"version": "0.7.0", | ||
"description": "Type safe HTTP client for the browser and node.js", | ||
@@ -5,0 +5,0 @@ "author": "m-mitsuhide <m.mitsuhide@amatelus.com>", |
@@ -6,2 +6,6 @@ <p align="right"> | ||
<div align="center"> | ||
<img src="https://aspidajs.github.io/aspida/assets/images/logo.png" alt="aspida" title="aspida" /> | ||
</div> | ||
<h1>aspida</h1> | ||
@@ -120,8 +124,6 @@ | ||
If baseurl is not specified, empty string is used by default | ||
```json | ||
{ | ||
"scripts": { | ||
"api:build": "aspida --build --baseurl https://examples.com" | ||
"api:build": "aspida --build" | ||
} | ||
@@ -137,3 +139,3 @@ } | ||
### Make HTTP request by giving token from application | ||
### Make HTTP request from application | ||
@@ -143,6 +145,3 @@ `src/index.ts` | ||
```typescript | ||
import axios from "axios" | ||
import api from "../apis/$api" | ||
axios.defaults.headers.common["X-Auth-Token"] = "YOUR TOKEN" | ||
;(async () => { | ||
@@ -152,8 +151,8 @@ const userId = 0 | ||
await api().v1.users.post({ name: "taro" }) | ||
await api().v1.users.post({ name: "mario" }) | ||
const res = await api().v1.users.get({ params: { limit } }) | ||
console.log(res) | ||
// req -> GET: https://examples.com/v1/users/?limit=10 | ||
// res -> { status: 200, data: [{ id: 0, name: 'taro' }], headers: {...} } | ||
// req -> GET: /v1/users/?limit=10 | ||
// res -> { status: 200, data: [{ id: 0, name: "mario" }], headers: {...} } | ||
@@ -164,4 +163,4 @@ const user = await api() | ||
console.log(user) | ||
// req -> GET: https://examples.com/v1/users/0 | ||
// res -> { id: 0, name: 'taro' } | ||
// req -> GET: /v1/users/0 | ||
// res -> { id: 0, name: "mario" } | ||
})() | ||
@@ -181,6 +180,25 @@ ``` | ||
### Overwrite baseURL | ||
### Set baseURL | ||
Set in axios to specify a baseURL different from the one set at build time in the application | ||
`src/index.ts` | ||
```typescript | ||
import axios from "axios" | ||
import api from "../apis/$api" | ||
axios.defaults.baseURL = "http://localhost:8080" | ||
;(async () => { | ||
const limit = 10 | ||
await api().v1.users.post({ name: "mario" }) | ||
const res = await api().v1.users.$get({ params: { limit } }) | ||
console.log(res) | ||
// req -> GET: http://localhost:8080/v1/users/?limit=10 | ||
// res -> [{ id: 0, name: "mario" }] | ||
})() | ||
``` | ||
### Request with token added to common header | ||
`src/index.ts` | ||
@@ -191,2 +209,4 @@ | ||
import api from "../apis/$api" | ||
axios.defaults.headers.common["X-Auth-Token"] = "YOUR TOKEN" | ||
;(async () => { | ||
@@ -196,30 +216,33 @@ const userId = 0 | ||
await api().v1.users.post({ name: "taro" }) | ||
await api().v1.users.post({ name: "mario" }) | ||
const res = await api().v1.users.get({ params: { limit } }) | ||
console.log(res) | ||
// req -> GET: https://examples.com/v1/users/?limit=10 | ||
// res -> { status: 200, data: [{ id: 0, name: 'taro' }], headers: {...} } | ||
const user = await api() | ||
.v1.users._userId(userId) | ||
.$get() | ||
console.log(user) | ||
// req -> GET: /v1/users/0 | ||
// res -> { id: 0, name: "mario" } | ||
})() | ||
``` | ||
axios.defaults.baseURL = "http://localhost:8080" | ||
### Request using axios Instance | ||
await api().v1.users.post({ name: "yoko" }) | ||
`src/index.ts` | ||
const localRes = await api().v1.users.get({ params: { limit } }) | ||
console.log(localRes) | ||
// req -> GET: http://localhost:8080/v1/users/?limit=10 | ||
// res -> { status: 200, data: [{ id: 0, name: 'yoko' }], headers: {...} } | ||
```typescript | ||
import axios from "axios" | ||
import api from "../apis/$api" | ||
;(async () => { | ||
const limit = 10 | ||
// using axios instance | ||
const instance = axios.create({ | ||
baseURL: "http://localhost:10000" | ||
}) | ||
const $api = api(instance) | ||
const client = axios.create({ baseURL: "http://localhost:10000" }) | ||
const $api = api(client) | ||
await $api.v1.users.post({ name: "mario" }) | ||
const instanceRes = await $api.v1.users.get({ params: { limit } }) | ||
console.log(instanceRes) | ||
const res = await $api.v1.users.$get({ params: { limit } }) | ||
console.log(res) | ||
// req -> GET: http://localhost:10000/v1/users/?limit=10 | ||
// res -> { status: 200, data: [{ id: 0, name: 'mario' }], headers: {...} } | ||
// res -> [{ id: 0, name: "mario" }] | ||
})() | ||
@@ -235,3 +258,3 @@ ``` | ||
npm run build | ||
node ./bin/index.js --build --baseurl=http://example.com | ||
node ./bin/index.js --build | ||
``` | ||
@@ -238,0 +261,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
284
50531
427