Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nepaul/rest-url-parser
Simplifies managing parameter-inclusive URLs, especially useful for applications handling REST APIs with URL-embedded resource identifiers.
https://github.com/nepaul/rest-url-parser
api-rest axios fetch got http http-client https needle request rest-api restful-api sse superagent url
Last synced: 8 days ago
JSON representation
Simplifies managing parameter-inclusive URLs, especially useful for applications handling REST APIs with URL-embedded resource identifiers.
- Host: GitHub
- URL: https://github.com/nepaul/rest-url-parser
- Owner: nepaul
- License: mit
- Created: 2023-06-06T02:31:34.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-06-14T02:40:04.000Z (over 1 year ago)
- Last Synced: 2024-04-22T12:23:38.694Z (7 months ago)
- Topics: api-rest, axios, fetch, got, http, http-client, https, needle, request, rest-api, restful-api, sse, superagent, url
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/@nepaul/rest-url-parser
- Size: 503 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Rest URL Parser
[![license](https://img.shields.io/github/license/nepaul/rest-url-parser)](https://github.com/nepaul/rest-url-parser)
[![npm](https://img.shields.io/npm/v/@nepaul/rest-url-parser)](https://www.npmjs.com/package/@nepaul/rest-url-parser)Only a function called `parseRequestURL()`.
Simplify the handling of URLs that contain parameters..
It's particularly useful for applications that deal with REST APIs where resource identifiers are embedded in the URL.
## Table of Contents
- [Rest URL Parser](#rest-url-parser)
- [Table of Contents](#table-of-contents)
- [Get Started](#get-started)
- [Install](#install)
- [Usage](#usage)
- [API](#api)
- [Contributing](#contributing)
- [License](#license)## Get Started
### Install
This project uses [node](http://nodejs.org) and [npm](https://npmjs.com). Please install them first.
```sh
npm install @nepaul/rest-url-parser
```## Usage
```javascript
import parseRequestURL from '@nepaul/rest-url-parser';const sourceConfig = {
url: '/user/:userId/post/:postId',
params: {
userId: '123',
postId: '456',
},
};const result = parseRequestURL(sourceConfig);
console.log(result);
```Use with Axios:
```javascript
import parseRequestURL from '@nepaul/rest-url-parser';const instance = axios.create(appConfig.httpClient);
const requestInterceptor = instance.interceptors.request.use(
function (config) {
const restConfig = parseRequestURL(config);
return restConfig;
},
function (error) {
return Promise.reject(error);
}
);instance.post('/user/:userId/post/:postId', {
userId: '123',
postId: '456',
});
```## API
**parseRequestURL(sourceConfig)**
This function takes a `sourceConfig` object and parses the `url` property for parameters. It returns the updated `sourceConfig`.
```javascript
parseRequestURL(sourceConfig);
```## Contributing
Your contributions and suggestions are heartily welcome.
Submit an issue or submit a pull request.Thanks to all the people who already contributed!
## License
[MIT](https://opensource.org/licenses/MIT)