Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hapinessjs/http-module
HTTP module for Hapiness framework
https://github.com/hapinessjs/http-module
Last synced: 7 days ago
JSON representation
HTTP module for Hapiness framework
- Host: GitHub
- URL: https://github.com/hapinessjs/http-module
- Owner: hapinessjs
- License: mit
- Created: 2017-04-11T08:14:02.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-28T07:47:15.000Z (about 6 years ago)
- Last Synced: 2024-11-08T04:39:20.912Z (about 2 months ago)
- Language: TypeScript
- Size: 174 KB
- Stars: 1
- Watchers: 7
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Http Module
`Http` Module for the [Hapiness](https://github.com/hapinessjs/hapiness) framework, allowing user to deal with `http` request.
## Table of contents
* [Using http module inside Hapiness application](#using-http-module-inside-hapiness-application)
* [Yarn or NPM it in your package.json](#yarn-or-npm-it-in-your-packagejson)
* [Import HttpModule](#import-httpmodule)
* [Use it anywhere](#use-it-anywhere)
* [Validate Response](#validateResponse-operator)
* [API in Detail](#api-in-detail)
* [Contributing](#contributing)
* [Change History](#change-history)
* [Maintainers](#maintainers)
* [License](#license)
## Using http module inside Hapiness application### `yarn` or `npm` it in your `package.json`
```bash
$ npm install --save @hapiness/http @hapiness/biim @hapiness/core rxjsor
$ yarn add @hapiness/http @hapiness/biim @hapiness/core rxjs
``````javascript
"dependencies": {
"@hapiness/biim": "^1.4.0",
"@hapiness/core": "^1.3.0",
"@hapiness/http": "^1.1.2",
"rxjs": "^5.5.6",
//...
}
//...
```### import `HttpModule`
```javascript
import { HapinessModule } from '@hapiness/core';
import { HttpModule } from '@hapiness/http';@HapinessModule({
version: '1.0.0',
declarations: [
LibWithHttpCalls
],
imports: [
HttpModule
]
})
class HapinessModuleNeedsHttpModule {}
```### use it anywhere
You can use `HttpService` anywhere in your module with **dependency injection**.
```javascript
import { Lib } from '@hapiness/core';
import { HttpService } from '@hapiness/http';@Lib()
class LibWithHttpCalls {
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
);
}
}
```[Back to top](#table-of-contents)
## validateResponse operator
Format your data with the Joi Schema validation and throw an error in the Observable if statusCode >= 400
`validateResponse(, [ignoredStatusCodes?])`
```javascript
import { Lib } from '@hapiness/core';
import { HttpService } from '@hapiness/http';
import '@hapiness/http/observable/add/validateResponse';@Lib()
class LibWithHttpCalls {
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
);
}
}
```## API in Detail
This module is an **encapsulation** of [Rx-Http-Request](https://github.com/njl07/rx-http-request) library to allow their features inside [Hapiness](https://github.com/hapinessjs/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](https://github.com/njl07/rx-http-request#api-in-detail).
[Back to top](#table-of-contents)
## Contributing
To set up your development environment:
1. clone the repo to your workspace,
2. in the shell `cd` to the main folder,
3. hit `npm or yarn install`,
4. 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`.[Back to top](#table-of-contents)
## Change History
* 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 `core` version
[Back to top](#table-of-contents)## Maintainers
Julien Fauville
Antoine Gomez
Sébastien Ritz
Nicolas Jessel
[Back to top](#table-of-contents)
## License
Copyright (c) 2017 **Hapiness** Licensed under the [MIT license](https://github.com/hapinessjs/http-module/blob/master/LICENSE.md).
[Back to top](#table-of-contents)