# nanorequests
[![PyPI version](https://badge.fury.io/py/nanorequests.svg)](https://badge.fury.io/py/nanorequests)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
## Overview
The simplest REST requests package for quick API integration.
The `nanorequests` package is a lightweight wrapper around the `requests` library, providing simplified HTTP request methods and exception handling.
## Requirements
The `nanorequests` package requires the following dependencies:
- `requests`
## Installation
You can install the `nanorequests` package using pip:
```bash
pip install nanorequests
```
## Usage
To use the `nanorequests` package, you can import it and create an instance of the `NanoRequests` class. This class provides static methods for making different types of HTTP requests.
```python
from nanorequests import NanoRequests
# Create an instance of NanoRequests
nr = NanoRequests()
# Make a GET request
response = nr.get('https://dummyjson.com/products')
# Make a POST request
payload = {'title': 'Nano Requests Python'}
response = nr.post('https://dummyjson.com/products/add', json=payload)
```
The `NanoRequests` class also handles different types of HTTP status codes and raises specific exceptions for each status code. You can catch these exceptions and handle them accordingly.
```python
from nanorequests import NanoRequests, NotFoundException
nr = NanoRequests()
try:
response = nr.get('https://dummyjson.com/products/99999')
except NotFoundException as e:
print(f"Product not found. Status code: {e.status_code}, Message: {e.message}")
```
## Examples
### GET Request
```python
response = nr.get('https://dummyjson.com/products/1')
print(response)
```
### POST Request
```python
payload = {'title': 'Viral Parmar'}
response = nr.post('https://dummyjson.com/products/add', json=payload)
print(response)
```
### PUT Request
```python
payload = {'title': 'Python Requests PIP'}
response = nr.put('https://dummyjson.com/products/1', json=payload)
print(response)
```
### DELETE Request
```python
response = nr.delete('https://dummyjson.com/products/1')
print(response)
```
### PATCH Request
```python
payload = {'title': 'Open Source Python'}
response = nr.patch('https://dummyjson.com/products/1', json=payload)
print(response)
```
## Features
The `nanorequests` package provides the following features:
- Simplified methods for making GET, POST, PUT, DELETE, and PATCH requests.
- Exception handling for different types of HTTP status codes.
- Support for JSON responses which are automatically parsed in case of 2XX response.
- Easy integration with the `requests` library.
### Handling Custom Exceptions
```python
from nanorequests import NanoRequests, NotFoundException, UnauthorizedException
try:
response = NanoRequests.get('https://dummyjson.com/products/1')
print(response)
except NotFoundException as e:
print(f'Resource not found: {e}')
except UnauthorizedException as e:
print(f'Unauthorized access: {e}')
except Exception as e:
print(f'An unexpected error occurred: {e}')
```
## Reference
For detailed information on each class and method, please refer to the source code and docstrings of the `nanorequests` package.
## Author
The `nanorequests` package is developed and maintained by Viral Parmar.
- https://twitter.com/viralparmarme
- https://github.com/viralparmarme
- https://pypi.org/user/viralparmar
## License
This project is licensed under the terms of the MIT license. Please see the [LICENSE.txt](https://github.com/viralparmarme/nanorequests/blob/main/LICENSE.txt) file for more information.
Feel free to raise an issue or pull request to support this project.
Raw data
{
"_id": null,
"home_page": "https://github.com/viralparmarme/nanorequests",
"name": "nanorequests",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "nanorequests viralparmarme viralparmar",
"author": "Viral Parmar",
"author_email": "viralparmarme@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/02/55/d882b4095444ad3af51c5f2b572db4dc696696c51bd623fa055bfc339f26/nanorequests-1.0.2.tar.gz",
"platform": null,
"description": "# nanorequests\n\n[![PyPI version](https://badge.fury.io/py/nanorequests.svg)](https://badge.fury.io/py/nanorequests)\n[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\n## Overview\n\nThe simplest REST requests package for quick API integration.\n\nThe `nanorequests` package is a lightweight wrapper around the `requests` library, providing simplified HTTP request methods and exception handling.\n\n## Requirements\n\nThe `nanorequests` package requires the following dependencies:\n\n- `requests`\n\n## Installation\n\nYou can install the `nanorequests` package using pip:\n\n```bash\npip install nanorequests\n```\n\n## Usage\n\nTo use the `nanorequests` package, you can import it and create an instance of the `NanoRequests` class. This class provides static methods for making different types of HTTP requests.\n\n```python\nfrom nanorequests import NanoRequests\n\n# Create an instance of NanoRequests\nnr = NanoRequests()\n\n# Make a GET request\nresponse = nr.get('https://dummyjson.com/products')\n\n# Make a POST request\npayload = {'title': 'Nano Requests Python'}\nresponse = nr.post('https://dummyjson.com/products/add', json=payload)\n```\n\nThe `NanoRequests` class also handles different types of HTTP status codes and raises specific exceptions for each status code. You can catch these exceptions and handle them accordingly.\n\n```python\nfrom nanorequests import NanoRequests, NotFoundException\n\nnr = NanoRequests()\n\ntry:\n response = nr.get('https://dummyjson.com/products/99999')\nexcept NotFoundException as e:\n print(f\"Product not found. Status code: {e.status_code}, Message: {e.message}\")\n```\n\n## Examples\n\n### GET Request\n\n```python\nresponse = nr.get('https://dummyjson.com/products/1')\nprint(response)\n```\n\n### POST Request\n\n```python\npayload = {'title': 'Viral Parmar'}\nresponse = nr.post('https://dummyjson.com/products/add', json=payload)\nprint(response)\n```\n\n### PUT Request\n\n```python\npayload = {'title': 'Python Requests PIP'}\nresponse = nr.put('https://dummyjson.com/products/1', json=payload)\nprint(response)\n```\n\n### DELETE Request\n\n```python\nresponse = nr.delete('https://dummyjson.com/products/1')\nprint(response)\n```\n\n### PATCH Request\n\n```python\npayload = {'title': 'Open Source Python'}\nresponse = nr.patch('https://dummyjson.com/products/1', json=payload)\nprint(response)\n```\n\n## Features\n\nThe `nanorequests` package provides the following features:\n\n- Simplified methods for making GET, POST, PUT, DELETE, and PATCH requests.\n- Exception handling for different types of HTTP status codes.\n- Support for JSON responses which are automatically parsed in case of 2XX response.\n- Easy integration with the `requests` library.\n\n### Handling Custom Exceptions\n\n```python\nfrom nanorequests import NanoRequests, NotFoundException, UnauthorizedException\n\ntry:\n response = NanoRequests.get('https://dummyjson.com/products/1')\n print(response)\nexcept NotFoundException as e:\n print(f'Resource not found: {e}')\nexcept UnauthorizedException as e:\n print(f'Unauthorized access: {e}')\nexcept Exception as e:\n print(f'An unexpected error occurred: {e}')\n```\n\n## Reference\n\nFor detailed information on each class and method, please refer to the source code and docstrings of the `nanorequests` package.\n\n## Author\n\nThe `nanorequests` package is developed and maintained by Viral Parmar.\n\n- https://twitter.com/viralparmarme\n- https://github.com/viralparmarme\n- https://pypi.org/user/viralparmar\n\n## License\n\nThis project is licensed under the terms of the MIT license. Please see the [LICENSE.txt](https://github.com/viralparmarme/nanorequests/blob/main/LICENSE.txt) file for more information.\nFeel free to raise an issue or pull request to support this project.\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "The simplest REST requests package for quick API integration",
"version": "1.0.2",
"project_urls": {
"Homepage": "https://github.com/viralparmarme/nanorequests"
},
"split_keywords": [
"nanorequests",
"viralparmarme",
"viralparmar"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "0255d882b4095444ad3af51c5f2b572db4dc696696c51bd623fa055bfc339f26",
"md5": "65c92f54e043073058736787c9c575b4",
"sha256": "ec20663e215ef7973463089ffd93518a9c3a28edecd69299c06540ad9e0dd08b"
},
"downloads": -1,
"filename": "nanorequests-1.0.2.tar.gz",
"has_sig": false,
"md5_digest": "65c92f54e043073058736787c9c575b4",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4971,
"upload_time": "2023-09-04T06:40:44",
"upload_time_iso_8601": "2023-09-04T06:40:44.030435Z",
"url": "https://files.pythonhosted.org/packages/02/55/d882b4095444ad3af51c5f2b572db4dc696696c51bd623fa055bfc339f26/nanorequests-1.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-04 06:40:44",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "viralparmarme",
"github_project": "nanorequests",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "nanorequests"
}