|
1 | | -## TODO |
| 1 | +[](https://badge.fury.io/js/angular2-expandable-list) |
| 2 | +[](https://github.com/prettier/prettier) |
| 3 | + |
| 4 | +# ngx-drupal8-rest |
| 5 | + |
| 6 | +> A wrapper library to connect to a Drupal8 based backend |
| 7 | +
|
| 8 | +## Prerequisites |
| 9 | + |
| 10 | +This project requires NodeJS (version 8 or later) and NPM. |
| 11 | +[Node](http://nodejs.org/) and [NPM](https://npmjs.org/) are really easy to install. |
| 12 | +To make sure you have them available on your machine, |
| 13 | +try running the following command. |
| 14 | + |
| 15 | +```sh |
| 16 | +$ npm -v && node -v |
| 17 | +6.14.17 |
| 18 | +v16.17.1 |
| 19 | +``` |
| 20 | + |
| 21 | +## Table of contents |
| 22 | + |
| 23 | +- [Project Name](#project-name) |
| 24 | + - [Prerequisites](#prerequisites) |
| 25 | + - [Table of contents](#table-of-contents) |
| 26 | + - [Getting Started](#getting-started) |
| 27 | + - [Installation](#installation) |
| 28 | + - [Usage](#usage) |
| 29 | + - [Serving the app](#serving-the-app) |
| 30 | + - [Running the tests](#running-the-tests) |
| 31 | + - [Building a distribution version](#building-a-distribution-version) |
| 32 | + - [Serving the distribution version](#serving-the-distribution-version) |
| 33 | + <!-- - [API](#api) |
| 34 | + - [useBasicFetch](#usebasicfetch) |
| 35 | + - [Options](#options) |
| 36 | + - [fetchData](#fetchdata) --> |
| 37 | + - [Contributing](#contributing) |
| 38 | + - [Credits](#credits) |
| 39 | + - [Built With](#built-with) |
| 40 | + - [Versioning](#versioning) |
| 41 | + - [Authors](#authors) |
| 42 | + - [License](#license) |
| 43 | + |
| 44 | +## Getting Started |
| 45 | + |
| 46 | +These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system. |
| 47 | + |
| 48 | +## Installation |
| 49 | + |
| 50 | +### For integrating on your project |
| 51 | + |
| 52 | +```sh |
| 53 | +$ npm i @makiwin/ngx-drupal8-rest |
| 54 | +``` |
| 55 | + |
| 56 | +**BEFORE YOU INSTALL:** please read the [prerequisites](#prerequisites) |
| 57 | + |
| 58 | +### For contribuiting to the project |
| 59 | + |
| 60 | +Start with cloning this repo on your local machine: |
| 61 | + |
| 62 | +```sh |
| 63 | +$ git clone https://github.com/Makiwin/ngx-drupal8-rest |
| 64 | +$ cd ngx-drupal8-rest |
| 65 | +``` |
| 66 | + |
| 67 | +To set up the library: |
| 68 | + |
| 69 | +```sh |
| 70 | +$ npm install |
| 71 | +``` |
| 72 | + |
| 73 | +Or if you prefer using Yarn: |
| 74 | + |
| 75 | +```sh |
| 76 | +$ yarn install |
| 77 | +``` |
| 78 | + |
| 79 | +## Usage |
| 80 | + |
| 81 | +### Serving the library |
| 82 | + |
| 83 | +```sh |
| 84 | +$ npm run watch:dev |
| 85 | +$ cd dist/ngx-drupal8-rest |
| 86 | +$ npm link |
| 87 | +``` |
| 88 | + |
| 89 | +### Using the library on your application |
| 90 | + |
| 91 | +go to the main folder of your application and type this command |
| 92 | +```sh |
| 93 | +$ npm link ngx-drupal8-rest |
| 94 | +``` |
| 95 | + |
| 96 | +### Building a distribution version |
| 97 | + |
| 98 | +```sh |
| 99 | +$ npm run publish |
| 100 | +``` |
| 101 | + |
| 102 | +This task will create a distribution version of the project |
| 103 | +inside your local `dist/` folder and will publish on npm |
| 104 | + |
| 105 | + |
| 106 | +<!-- ## API |
| 107 | +
|
| 108 | +### useBasicFetch |
| 109 | +
|
| 110 | +```js |
| 111 | +useBasicFetch(url: string = '', delay: number = 0) |
| 112 | +``` |
| 113 | +
|
| 114 | +Supported options and result fields for the `useBasicFetch` hook are listed below. |
| 115 | +
|
| 116 | +#### Options |
| 117 | +
|
| 118 | +`url` |
| 119 | +
|
| 120 | +| Type | Default value | |
| 121 | +| --- | --- | |
| 122 | +| string | '' | |
| 123 | +
|
| 124 | +If present, the request will be performed as soon as the component is mounted |
| 125 | +
|
| 126 | +Example: |
| 127 | +
|
| 128 | +```tsx |
| 129 | +const MyComponent: React.FC = () => { |
| 130 | + const { data, error, loading } = useBasicFetch('https://api.icndb.com/jokes/random'); |
| 131 | +
|
| 132 | + if (error) { |
| 133 | + return <p>Error</p>; |
| 134 | + } |
| 135 | +
|
| 136 | + if (loading) { |
| 137 | + return <p>Loading...</p>; |
| 138 | + } |
| 139 | +
|
| 140 | + return ( |
| 141 | + <div className="App"> |
| 142 | + <h2>Chuck Norris Joke of the day</h2> |
| 143 | + {data && data.value && <p>{data.value.joke}</p>} |
| 144 | + </div> |
| 145 | + ); |
| 146 | +}; |
| 147 | +``` |
| 148 | +
|
| 149 | +`delay` |
| 150 | +
|
| 151 | +| Type | Default value | Description | |
| 152 | +| --- | --- | --- | |
| 153 | +| number | 0 | Time in milliseconds | |
| 154 | +
|
| 155 | +If present, the request will be delayed by the given amount of time |
| 156 | +
|
| 157 | +Example: |
| 158 | +
|
| 159 | +```tsx |
| 160 | +type Joke = { |
| 161 | + value: { |
| 162 | + id: number; |
| 163 | + joke: string; |
| 164 | + }; |
| 165 | +}; |
| 166 | +
|
| 167 | +const MyComponent: React.FC = () => { |
| 168 | + const { data, error, loading } = useBasicFetch<Joke>('https://api.icndb.com/jokes/random', 2000); |
| 169 | +
|
| 170 | + if (error) { |
| 171 | + return <p>Error</p>; |
| 172 | + } |
| 173 | +
|
| 174 | + if (loading) { |
| 175 | + return <p>Loading...</p>; |
| 176 | + } |
| 177 | +
|
| 178 | + return ( |
| 179 | + <div className="App"> |
| 180 | + <h2>Chuck Norris Joke of the day</h2> |
| 181 | + {data && data.value && <p>{data.value.joke}</p>} |
| 182 | + </div> |
| 183 | + ); |
| 184 | +}; |
| 185 | +``` |
| 186 | +
|
| 187 | +### fetchData |
| 188 | +
|
| 189 | +```js |
| 190 | +fetchData(url: string) |
| 191 | +``` |
| 192 | +
|
| 193 | +Perform an asynchronous http request against a given url |
| 194 | +
|
| 195 | +```tsx |
| 196 | +type Joke = { |
| 197 | + value: { |
| 198 | + id: number; |
| 199 | + joke: string; |
| 200 | + }; |
| 201 | +}; |
| 202 | +
|
| 203 | +const ChuckNorrisJokes: React.FC = () => { |
| 204 | + const { data, fetchData, error, loading } = useBasicFetch<Joke>(); |
| 205 | + const [jokeId, setJokeId] = useState(1); |
| 206 | +
|
| 207 | + useEffect(() => { |
| 208 | + fetchData(`https://api.icndb.com/jokes/${jokeId}`); |
| 209 | + }, [jokeId, fetchData]); |
| 210 | +
|
| 211 | + const handleNext = () => setJokeId(jokeId + 1); |
| 212 | +
|
| 213 | + if (error) { |
| 214 | + return <p>Error</p>; |
| 215 | + } |
| 216 | +
|
| 217 | + const jokeData = data && data.value; |
| 218 | +
|
| 219 | + return ( |
| 220 | + <div className="Comments"> |
| 221 | + {loading && <p>Loading...</p>} |
| 222 | + {!loading && jokeData && ( |
| 223 | + <div> |
| 224 | + <p>Joke ID: {jokeData.id}</p> |
| 225 | + <p>{jokeData.joke}</p> |
| 226 | + </div> |
| 227 | + )} |
| 228 | + {!loading && jokeData && !jokeData.joke && <p>{jokeData}</p>} |
| 229 | + <button disabled={loading} onClick={handleNext}> |
| 230 | + Next Joke |
| 231 | + </button> |
| 232 | + </div> |
| 233 | + ); |
| 234 | +}; |
| 235 | +``` --> |
| 236 | + |
| 237 | +## Contributing |
| 238 | + |
| 239 | +Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us. |
| 240 | + |
| 241 | +1. Fork it! |
| 242 | +2. Create your feature branch: `git checkout -b my-new-feature` |
| 243 | +3. Add your changes: `git add .` |
| 244 | +4. Commit your changes: `git commit -am 'Add some feature'` |
| 245 | +5. Push to the branch: `git push origin my-new-feature` |
| 246 | +6. Submit a pull request :sunglasses: |
| 247 | + |
| 248 | +## Credits |
| 249 | + |
| 250 | +TODO: Write credits |
| 251 | + |
| 252 | +## Built With |
| 253 | + |
| 254 | +* VsCode |
| 255 | +* npm |
| 256 | +* Love :heart: |
| 257 | + |
| 258 | +## Versioning |
| 259 | + |
| 260 | +We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/your/project/tags). |
| 261 | + |
| 262 | +## Authors |
| 263 | + |
| 264 | +* **Wassem Keddah** - *Initial work* - [wnabil](https://github.com/wnabil) |
| 265 | +* **Massimiliano Vinciprova** - [Makiwin](https://github.com/Makiwin) |
| 266 | + |
| 267 | +See also the list of [contributors](https://github.com/Makiwin/ngx-drupal8-rest/graphs/contributors) who participated in this project. |
| 268 | + |
| 269 | +## License |
| 270 | + |
| 271 | +[MIT License](https://mit-license.org/2019) |
0 commit comments