
Security News
TeamPCP and BreachForums Launch $1,000 Contest for Supply Chain Attacks
TeamPCP and BreachForums are promoting a Shai-Hulud supply chain attack contest with a $1,000 prize for the biggest package compromise.
Chained and declarative HTTP client based on the browser Fetch API
The latest version of Chrome, Firefox, and Safari.
npm i fly-http
import http from 'fly-http'
(async () => {
const res = await http
.p('https://cnodejs.org/api/v1')
.p('topics')
.q('page', 2)
.q('tab', 'good')
.q('limit', 5)
.get()
console.log('res', res)
})()
Add path segment to request url including non-encoded path segment.
http
.path('https://cnodejs.org')
.path('api')
.path('v1')
.path('topics')
.get()
you can also make one path with the slash:
http
.path('https://cnodejs.org/api/v1/topics')
.get()
Alias for path().
http
.p('https://cnodejs.org')
.p('api')
.p('v1')
.p('topics')
.get()
Add query parameter to request url.
http
.path('https://cnodejs.org/api/v1')
.path('topics')
.query('page', 2)
.query('tab', 'good')
.query('limit', 5)
.get()
Alias for query().
http
.p('https://cnodejs.org/api/v1')
.p('topics')
.q('page', 2)
.q('tab', 'good')
.q('limit', 5)
.get()
Accept object as params.
http
.p('https://cnodejs.org/api/v1')
.p('topics')
.queryAll({
'page': 2,
'tab': 'good',
'limit': 5
})
.get()
Add header to request.
http
.p('account')
.p('users')
.p(userId)
.p('state')
.header('Content-Type', 'text/plain')
.put('LOCKED');
You can also define custom header by this method:
.header('X-TenantId', companyId)
Convenience method for setting the "Authorization" header, same with:
.header('Authorization', value)
.auth('Bearer eyJhbGciOiJIUzI1NiIs')
Set the content type of the body.
.content('multipart/form-data')
Convenience method for sending data as plain text, same with:
.content('text/plain')
Convenience method for sending data as json, same with:
.content('application/json')
Set the Accept header.
.accept('text/csv')
Convenience method for getting plain text response, same with:
.accept('text/plain')
Convenience method for getting XML response, same with:
.accept('text/plain')
Append formData params and set the content-type header to multipart/form-data automatically.
http
.path('flipper/v0/flip')
.path('order')
.append('quotation', file)
.accept('application/vnd.oasis.ubl+json')
.post();
Convert the javascript object to a FormData and set the content-type header to multipart/form-data automatically.
const data = {
pony: true,
text: 'abc'
}
http
.path('...')
.formData(data)
.post()
Convert the input to an url encoded string and set the content-type header to application/x-www-form-urlencoded automatically.
const input = {
pony: true,
tim: { isFat: false }
}
const alreadyEncodedForm = 'pony=true&tim=%7B%22isFat%22%3Afalse%7D'
http.path('...').formUrl(form).post()
http.path('...').formUrl(alreadyEncodedForm).post()
Send request.
supported methods: POST, GET, POST, PUT, DELETE, PATCH, etc.
Send GET request, same with:
.send('GET', null)
Send POST request, same with:
.send('POST', body)
Send PUT request, same with:
.send('PUT', body)
Send PATCH request, same with:
.send('PATCH', body)
Send HEAD request, same with:
.send('HEAD', null)
Send DELETE request, same with:
.send('DELETE', null)
Makes this request cache for ttl milliseconds.
Clear the request cache map.
import { clearCache } from 'fly-http'
clearCache()
Callback that gets invoked with string url before sending.
Note: It can only change headers and body of the request.
Return a promise for the response (including status code and headers), rather than for just the response data.
http
.path(url)
.enrichResponse()
.get()
File will be named by following priority:
// file will be downloaded and named 'prop-types.js'
http
.p('https://cdn.bootcss.com/prop-types/15.6.1/prop-types.js')
.download()
// file will be downloaded and named 'types.js'
http
.p('https://cdn.bootcss.com/prop-types/15.6.1/prop-types.js')
.download('types.js')
// you can also download file by chained path style
http
.p('https://cdn.bootcss.com')
.p('prop-types')
.p('15.6.1')
.p('prop-types.js')
.download()
Set Fetch API options, this options method will replace other options you defined.
http
.p('...')
.options({credentials: 'include'})
.post(body)
MIT © Kimi Gao
FAQs
Chained and declarative HTTP client based on the browser Fetch API
We found that fly-http demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
TeamPCP and BreachForums are promoting a Shai-Hulud supply chain attack contest with a $1,000 prize for the biggest package compromise.

Security News
Packagist urges PHP projects to update Composer after a GitHub token format change exposed some GitHub Actions tokens in CI logs.

Research
GemStuffer abuses RubyGems as an exfiltration channel, packaging scraped UK council portal data into junk gems published from new accounts.