Http Module for the Hapiness framework, allowing user to deal with http request.
- Using http module inside Hapiness application
- Validate Response
- API in Detail
- Contributing
- Change History
- Maintainers
- License
$ npm install --save @hapiness/http @hapiness/biim @hapiness/core rxjs
or
$ yarn add @hapiness/http @hapiness/biim @hapiness/core rxjs"dependencies": {"@hapiness/biim": "^1.4.0","@hapiness/core": "^1.3.0","@hapiness/http": "^1.1.2","rxjs": "^5.5.6",//...}//...import{HapinessModule}from'@hapiness/core';import{HttpModule}from'@hapiness/http';
@HapinessModule({version: '1.0.0',declarations: [LibWithHttpCalls],imports: [HttpModule]})classHapinessModuleNeedsHttpModule{}You can use HttpService anywhere in your module with dependency injection.
import{Lib}from'@hapiness/core';import{HttpService}from'@hapiness/http';
@Lib()classLibWithHttpCalls{constructor(private_http: HttpService){}crawlWebPage(): void{this._http.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);}}Format your data with the Joi Schema validation and throw an error in the Observable if statusCode >= 400
validateResponse(<Joi.Schema>, [ignoredStatusCodes?])
import{Lib}from'@hapiness/core';import{HttpService}from'@hapiness/http';import'@hapiness/http/observable/add/validateResponse';
@Lib()classLibWithHttpCalls{constructor(private_http: HttpService){}crawlWebPage(): void{this._http.get('http://my-api/data').validateResponse(MySchema).subscribe((data)=>console.log(data),(err)=>console.error(err)// Show error in console);}}This module is an encapsulation of Rx-Http-Request library to allow their features inside Hapiness framework.
Methods implemented are:
.request.get(uri[, options]).getBuffer(uri[, options]).post(uri[, options]).put(uri[, options]).patch(uri[, options]).delete(uri[, options]).head(uri[, options]).jar().cookie(str)
If you want to have all details for these methods, see Rx-Http-Request's API details.
To set up your development environment:
- clone the repo to your workspace,
- in the shell
cdto the main folder, - hit
npm or yarn install, - run
npm or yarn run test.- It will lint the code and execute all tests.
- The test coverage report can be viewed from
./coverage/lcov-report/index.html.
- v1.1.2 (2018-01-29)
- Latest packages' versions.
- Documentation.
- Fix error message on body.
- v1.1.1 (2017-11-20)
- Latest packages' versions.
- Documentation.
- Change packaging process.
- v1.0.0 (2017-10-12)
- First stable version
- Implementation of all features.
- Version related to
coreversion
| Julien Fauville | Antoine Gomez | Sébastien Ritz | Nicolas Jessel |
Copyright (c) 2017 Hapiness Licensed under the MIT license.

