PicGo-Core
PicGo-Core copied to clipboard
【refactor】Refactoring Request with Got
Since the package request was deprecated, PicGo-Core will replace it with got which is active and maintained.
The timeline is the following:
- v1.5.0: replace the
request
withgot
, but the API exposed to the outside world is still consistent. You can still usectx.Request.request
. However, it will be warned withdeprecated
. The new api isctx.request
. - v1.6.0: just simply use
ctx.request
is OK, though therequest
lib will be changed togot
. And you can't usectx.Request.request
anymore. - v2.0.0: will add an adaptor layer for web & node environment. In the web env, we will use
axios
, in the node env, we will usegot
. But the outside world is stillctx.request
.
@Molunerfinn So all the uploaders will have to change their implementation?
@Molunerfinn So all the uploaders will have to change their implementation?
Yes. In v1.5.0
, we will provide both ctx.Reqeust.request
& ctx.request
for developers to change their implementation. It will be a long time since v1.5.0 upgrade to v1.6.0 so developers can have enough time to upgrade. But in v1.6.0, the ctx.Request.request
will be removed.
Before v1.5.0, PicGo-Core will provide a way to install a specific version of plugins.
@Molunerfinn This is very nice~
v2.0.0: will add an adaptor layer for web & node environment. In the web env, we will use axios, in the node env, we will use got. But the outside world is still ctx.request.
@Molunerfinn At the present, PicGo CLI (ctx.cmd
) and plugin install feature (ctx.pluginHandler
) is coupled in PicGo class, all of these only works in node environment, so it will be difficult to support web environment. Also, now that we will migarte axios finally, why not using axios
now (axios
supports both web and node environment), but using got
?
yes we can use axios
The next alpha version of PicGo-Core will change request to axios.
For plugin developers:
- the old request options will also be available but will not be 100% OK, it's recommend to change to new axios options.
- support axios options. However, cause we need to be compatible with the old request options, so if your options do not provide
resolveWithFullResponse
, the result ofctx.request
will be just data. See the following examples:
const res = await ctx.request({
// other options
resolveWithFullResponse: true
})
console.log(res) // { status, data, headers, config, request }
const res2 = await ctx.request({
// other options
})
console.log(res2) // { ...data }
v1.5.0-alpha.9 is release
See docs: https://picgo.github.io/PicGo-Core-Doc/zh/api/#request