Skip to content

Commit

Permalink
Develop (#1)
Browse files Browse the repository at this point in the history
* inital develop branch and barebone file

* added a working
 example

* finished the first version. Need to work on github banners
then publish to npmjs next

* removed unnecessary file

* added newline at the end of file
  • Loading branch information
mohsenari committed Sep 4, 2018
1 parent 6496ea6 commit 0babe52
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 389 deletions.
69 changes: 38 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,44 @@
## Welcome to GitHub Pages
# Nodeh

You can use the [editor on GitHub](https://github.com/mohsenari/nodejsWebApp/edit/master/README.md) to maintain and preview the content for your website in Markdown files.
Nodeh (pronounced node-h) is a simple utility class that wraps Axios' HTTP request module to simplify the usage by chaining methods which at then end, the code is readable and easy to understand.

Whenever you commit to this repository, GitHub Pages will run [Jekyll](https://jekyllrb.com/) to rebuild the pages in your site, from the content in your Markdown files.
## Installation

### Markdown

Markdown is a lightweight and easy-to-use syntax for styling your writing. It includes conventions for

```markdown
Syntax highlighted code block

# Header 1
## Header 2
### Header 3

- Bulleted
- List

1. Numbered
2. List

**Bold** and _Italic_ and `Code` text

[Link](url) and ![Image](src)
```js
npm i Nodeh
```

For more details see [GitHub Flavored Markdown](https://guides.github.com/features/mastering-markdown/).

### Jekyll Themes

Your Pages site will use the layout and styles from the Jekyll theme you have selected in your [repository settings](https://github.com/mohsenari/nodejsWebApp/settings). The name of this theme is saved in the Jekyll `_config.yml` configuration file.

### Support or Contact
## Usage

Nodeh is a class so you need to import and then instantiate it. Then the methods can be chained together to complete an HTTP request.
```js
const nodeh = require('nodeh');


// example 1: GET request
let get_request = new nodeh();
get_request
.addUrl('http://bing.com') //add the url of the request
.send() //send the request
.then( (result) => { console.log(result.data) } ) //what happens on success
.catch( (error) => { console.log(error) } ) //what happens on error

// example 2: POST request
let post_request = new nodeh();
request
.addUrl('https://reqres.in') //can also use addUrl('https://reqres.in/api/user')
.addPath('/api/users') //and don't call addPath('/api/users')
.addMethod('POST')
.addHeaders({"Accept": "application/json"})
.addData({
name: "Channing Tatum",
quote: "My name is Jeff"
})
.send()
.then( result => { console.log(result.data) } )
.catch( error => { console.log(error) } )
```
---
Go ahead and give it a try :)

Having trouble with Pages? Check out our [documentation](https://help.github.com/categories/github-pages-basics/) or [contact support](https://github.com/contact) and we’ll help you sort it out.
Please let me know of any feedback at [@mohsenari](https://twitter.com/mohsenari) on Twitter or [@mohsenari](https://github.com/mohsenari) on Github.
1 change: 0 additions & 1 deletion _config.yml

This file was deleted.

21 changes: 21 additions & 0 deletions example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const nodeh = require('./nodeh.js');


let request = new nodeh();

// request
// .addUrl('http://bing.com')
// .send()
// .then( (res) => { console.log(res.data) } );

request
.addUrl('https://reqres.in')
.addPath('/api/users')
.addMethod('POST')
.addHeaders({"Accept": "application/json"})
.addData({
name: "Channing Tatum",
quote: "My name is Jeff"
})
.send()
.then( res => {console.log(res.data)});
54 changes: 54 additions & 0 deletions nodeh.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const axios = require('axios');

class Nodeh {
constructor() {
this.baseUrl = "";
this.path = "";
this.method = "GET"
this.data = {};
this.headers = {};
this.timeout = 20000;

}

addUrl (url) {
this.baseUrl = url;
return this;
}

addPath(path) {
this.path = path;
return this;
}

addMethod(method) {
this.method = method;
return this;
}

addData(data) {
this.data = data;
return this;
}

addHeaders(headers) {
this.headers = headers;
return this;
}

addTimeout(timeout) {
this.timeout = timeout;
return this;
}

send() {
const request = {
method: this.method,
url: this.baseUrl + this.path,
data: this.data
};
return axios.request(request)
}
}

module.exports = Nodeh;

0 comments on commit 0babe52

Please sign in to comment.