Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@akanass/rx-http-request
Advanced tools
The world-famous HTTP client Request now RxJS compliant, wrote in Typescript | ES6 for client and server side.
The world-famous HTTP client Request now RxJS compliant, wrote in full Typescript | ES6 for client and server side.
$ npm install --save @akanass/rx-http-request rxjs
or
$ yarn add @akanass/rx-http-request rxjs
Rx-Http-Request is designed to be the simplest way possible to make http calls.
It's fully Typescript
| ES6
wrotten so you can import it :
import {RxHR} from "@akanass/rx-http-request";
or use CommonJS
:
const RxHR = require('@akanass/rx-http-request').RxHR;
Now, it's easy to perform a HTTP
request:
RxHR.get('http://www.google.fr').subscribe(
(data) => {
if (data.response.statusCode === 200) {
console.log(data.body); // Show the HTML for the Google homepage.
}
},
(err) => console.error(err) // Show error in console
);
Rx-Http-Request can be used in your favorite browser to have all features in your own front application.
Just import browser/index.js
script and enjoy:
<script src="node_modules/@akanass/rx-http-request/browser/index.js" type="application/javascript"></script>
<script type="application/javascript">
const RxHR = rhr.RxHR;
RxHR.get('http://www.google.fr').subscribe(
function(data){
if (data.response.statusCode === 200) {
console.log(data.body); // Show the HTML for the Google homepage.
}
},
function(err){
console.error(err) // Show error in console
}
);
</script>
Browser version is a standalone version so you just need to copy/paste
file from node_modules/@akanass/rx-http-request/browser/index.js
when you want to create your bundle and change path to it.
If you want to include this library inside a project builds with webpack
for a client
application, you must add this configuration inside your webpack configuration
:
{
target: "web",
node: {
fs: "empty",
net: "empty",
tls: "empty"
}
}
For a server
application, target
will be node
, node
block in configuration doesn't exist and uglify
plugin must be disabled
.
Rx-Http-Request uses Request API to perform calls and returns RxJS.Observable.
All options to pass to API methods can be found here.
All methods to execute on response object can be found here.
.request
Returns the original Request API to perform calls without RxJS.Observable
response but with a callback method.
import {RxHR} from '@akanass/rx-http-request';
RxHR.request({uri: 'http://www.google.fr'}, (error, response, body) => {
if (!error && response.statusCode == 200) {
console.log(body); // Show the HTML for the Google homepage.
}
});
.defaults(options)
This method returns a wrapper around the normal Rx-Http-Request API that defaults to whatever options you pass to it.
Parameters:
options (required): Original Request
options
object with default values foreach next requests
Response:
new
RxHttpRequest
instance
Note: RxHR.defaults()
does not modify the global API; instead, it returns a wrapper that has your default settings applied to it.
Note: You can call .defaults()
on the wrapper that is returned from RxHR.defaults()
to add/override defaults that were previously defaulted.
For example:
// requests using baseRequest will set the 'x-token' header
const baseRequest = RxHR.defaults({
headers: {'x-token': 'my-token'}
});
// requests using specialRequest will include the 'x-token' header set in
// baseRequest and will also include the 'special' header
const specialRequest = baseRequest.defaults({
headers: {special: 'special value'}
});
.get(uri[, options])
Performs a request with get
http method.
Parameters:
- uri (required): The
uri
where request will be performed- options (optional): Original Request
options
object
Response:
RxJS.Observable instance
import {RxHR} from '@akanass/rx-http-request';
RxHR.get('http://www.google.fr').subscribe(
(data) => {
if (data.response.statusCode === 200) {
console.log(data.body); // Show the HTML for the Google homepage.
}
},
(err) => console.error(err) // Show error in console
);
import {RxHR} from '@akanass/rx-http-request';
const options = {
qs: {
access_token: 'xxxxx xxxxx' // -> uri + '?access_token=xxxxx%20xxxxx'
},
headers: {
'User-Agent': 'Rx-Http-Request'
},
json: true // Automatically parses the JSON string in the response
};
RxHR.get('https://api.github.com/user/repos', options).subscribe(
(data) => {
if (data.response.statusCode === 200) {
console.log(data.body); // Show the JSON response object.
}
},
(err) => console.error(err) // Show error in console
);
.getBuffer(uri[, options])
Performs a request with get
http method and returns a buffer in response body. Very useful to crawl data from a stream.
Parameters:
- uri (required): The
uri
where request will be performed- options (optional): Original Request
options
object
Response:
RxJS.Observable instance
import {RxHR} from '@akanass/rx-http-request';
RxHR.getBuffer('https://portalstoragewuprod2.azureedge.net/vision/Analysis/1-1.jpg').subscribe(
(data) => {
if (data.response.statusCode === 200) {
console.log(data.response.headers['content-type']); // Show image content-type.
console.log(data.body); // Show image buffer array.
}
},
(err) => console.error(err) // Show error in console
);
.post(uri[, options])
Performs a request with post
http method.
Parameters:
- uri (required): The
uri
where request will be performed- options (optional): Original Request
options
object
Response:
RxJS.Observable instance
import {RxHR} from '@akanass/rx-http-request';
const options = {
body: {
some: 'payload'
},
json: true // Automatically stringifies the body to JSON
};
RxHR.post('http://posttestserver.com/posts', options).subscribe(
(data) => {
if (data.response.statusCode === 201) {
console.log(data.body); // Show the JSON response object.
}
},
(err) => console.error(err) // Show error in console
);
import {RxHR} from '@akanass/rx-http-request';
const options = {
form: {
some: 'payload' // Will be urlencoded
},
headers: {
/* 'content-type': 'application/x-www-form-urlencoded' */ // Set automatically
}
};
RxHR.post('http://posttestserver.com/posts', options).subscribe(
(data) => {
if (data.response.statusCode === 201) {
console.log(data.body); // POST succeeded...
}
},
(err) => console.error(err) // Show error in console
);
.put(uri[, options])
Performs a request with put
http method.
Parameters:
- uri (required): The
uri
where request will be performed- options (optional): Original Request
options
object
Response:
RxJS.Observable instance
import {RxHR} from '@akanass/rx-http-request';
RxHR.put(uri).subscribe(...);
.patch(uri[, options])
Performs a request with patch
http method.
Parameters:
- uri (required): The
uri
where request will be performed- options (optional): Original Request
options
object
Response:
RxJS.Observable instance
import {RxHR} from '@akanass/rx-http-request';
RxHR.patch(uri).subscribe(...);
.delete(uri[, options])
Performs a request with delete
http method.
Parameters:
- uri (required): The
uri
where request will be performed- options (optional): Original Request
options
object
Response:
RxJS.Observable instance
import {RxHR} from '@akanass/rx-http-request';
RxHR.delete(uri).subscribe(...);
.head(uri[, options])
Parameters:
- uri (required): The
uri
where request will be performed- options (optional): Original Request
options
object
Response:
RxJS.Observable instance
Performs a request with head
http method.
import {RxHR} from '@akanass/rx-http-request';
RxHR.head(uri).subscribe(...);
.options(uri[, options])
Parameters:
- uri (required): The
uri
where request will be performed- options (optional): Original Request
options
object
Response:
RxJS.Observable instance
Performs a request with options
http method.
import {RxHR} from '@akanass/rx-http-request';
RxHR.options(uri).subscribe(...);
.jar()
Creates a new RxCookieJar
instance
Response:
RxJS.Observable instance
import {RxHR} from '@akanass/rx-http-request';
RxHR.jar().subscribe(...);
.cookie(str)
Creates a new cookie
Parameters:
- str (required): The
string
representation of the cookie
Response:
RxJS.Observable instance
import {RxHR} from '@akanass/rx-http-request';
RxHR.cookie('key1=value1').subscribe(...);
To set up your development environment:
cd
to the main folder,npm or yarn install
,npm or yarn run test
.
./coverage/lcov-report/index.html
.unused
packages error in compilationrxjs
operators instead of manual creationrxjs
in peerDependencies and need to be installed manuallyno-shadowed-variable
value in tslint
configtsconfig
filesgetBuffer
method if no uri
providedrequest typings
installationRequest
version to v2.80.0
RxJS
and Request
RxJS
, only Observable
Typescript
typings
support@akanass/rx-http-request
Copyright (c) 2019 Nicolas Jessel Licensed under the MIT license.
FAQs
The world-famous HTTP client Request now RxJS compliant, wrote in Typescript | ES6 for client and server side.
We found that @akanass/rx-http-request 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.