239 lines
4 KiB
Markdown
239 lines
4 KiB
Markdown
## Well Service End Points
|
||
|
||
## JWT related end-points
|
||
### 1. Get token
|
||
**URL:**
|
||
.../token/
|
||
**Method**:
|
||
POST
|
||
**Input**:
|
||
1. Request body:
|
||
```python
|
||
{
|
||
"username": "<username>",
|
||
"password": "<password>"
|
||
}
|
||
```
|
||
**How it works?**
|
||
|
||
### To optain the jwt Token for the first time from other services
|
||
```python
|
||
import requests
|
||
url = 'http://<well_service_url>/token/'
|
||
|
||
credentials = {
|
||
"username": "your_username",
|
||
"password": "your_password"
|
||
}
|
||
|
||
response = requests.post(url, data=credentials)
|
||
token = response.json().get('access')
|
||
```
|
||
Store this token to use in future requests like this:
|
||
```python
|
||
headers = {
|
||
'Authorization': f'Bearer {token}',
|
||
}
|
||
response = requests.post('http://<well_service_url>/<...>/', headers=headers, json=data_to_send)
|
||
```
|
||
|
||
## Well related end-points
|
||
### 1. create
|
||
**URL:**
|
||
.../wells/create/
|
||
**Method**:
|
||
POST
|
||
**Input**:
|
||
1. Request body:
|
||
```python
|
||
{
|
||
"license_code": "<some_data>",
|
||
"representor": "<user_id>",
|
||
"subscriptionـcode": "<some_data>",
|
||
# or some other well data
|
||
}
|
||
```
|
||
2. Header:
|
||
```python
|
||
{"Authorization" : f"Bearer {access_token}" }
|
||
```
|
||
**Output:**
|
||
1. OK:
|
||
```python
|
||
({"data": "<serializer.data>"},
|
||
status=status.HTTP_200_OK)
|
||
```
|
||
2. Errors:
|
||
```python
|
||
1 ({"message":f'<{data["license_code"]} already exists>'},
|
||
status=status.HTTP_409_CONFLICT)
|
||
|
||
2 ({"message": serializer.errors},
|
||
status=status.HTTP_400_BAD_REQUEST)
|
||
|
||
3 ({"message": "Internal Server Error",
|
||
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||
```
|
||
---------
|
||
### 2. Get by ID
|
||
**URL:**
|
||
.../wells/<well_id>/
|
||
**Method**:
|
||
GET
|
||
**Input**:
|
||
1. URL: well id
|
||
2. Header:
|
||
```python
|
||
{"Authorization" : f"Bearer {access_token}" }
|
||
```
|
||
**Output:**
|
||
1. OK:
|
||
```python
|
||
({"data": "<serializer.data>"},
|
||
status=status.HTTP_200_OK)
|
||
```
|
||
2. Errors:
|
||
```python
|
||
1 ({"message": "Not Found"},
|
||
status=status.HTTP_404_NOT_FOUND)
|
||
|
||
2 ({"message": "Internal Server Error",
|
||
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||
```
|
||
-------------
|
||
### 3. Get All
|
||
**URL:**
|
||
.../wells/
|
||
**Method**:
|
||
GET
|
||
**Input**:
|
||
1. Header:
|
||
```python
|
||
{"Authorization" : f"Bearer {access_token}" }
|
||
```
|
||
**Output:**
|
||
1. OK:
|
||
```python
|
||
({"data": "<serializer.data>"},
|
||
status=status.HTTP_200_OK)
|
||
```
|
||
2. Errors:
|
||
```python
|
||
1 ({"message": "Internal Server Error",
|
||
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||
```
|
||
---------------
|
||
### 4. Delete
|
||
**URL:**
|
||
...wells/<well_id>/delete/
|
||
|
||
**Method**:
|
||
DELETE
|
||
|
||
**Input**:
|
||
1. URL: well id
|
||
2. Header:
|
||
```python
|
||
{"Authorization" : f"Bearer {access_token}" }
|
||
```
|
||
**Output:**
|
||
1. OK:
|
||
```python
|
||
({"data": "<serializer.data>",
|
||
"message": f"Successfully removed {instance.license_code}"},
|
||
status=status.HTTP_200_OK)
|
||
```
|
||
2. Errors:
|
||
```python
|
||
|
||
1.({"message": "Not Found"},
|
||
status=status.HTTP_404_NOT_FOUND)
|
||
|
||
2 ({"message": "Internal Server Error",
|
||
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||
```
|
||
---------
|
||
|
||
### 5. Update
|
||
**URL:**
|
||
...wells/<well_id>/update/
|
||
|
||
**Method**:
|
||
PUT
|
||
|
||
**Input**:
|
||
1. URL: well id
|
||
2. Header:
|
||
```python
|
||
{"Authorization" : f"Bearer {access_token}" }
|
||
```
|
||
3. Request body:
|
||
```python
|
||
{
|
||
"license_code": "<some_data>",
|
||
"representor": "<user_id>",
|
||
"subscriptionـcode": "<some_data>",
|
||
# or some other well data
|
||
}
|
||
```
|
||
**Output:**
|
||
5. OK:
|
||
```python
|
||
(
|
||
{"data": "<serializer.data>"},
|
||
status=status.HTTP_200_OK)
|
||
```
|
||
6. Errors:
|
||
```python
|
||
|
||
7. ({"message": "Not Found"},
|
||
status=status.HTTP_404_NOT_FOUND)
|
||
|
||
8. ({"message":serializer.errors},
|
||
status=status.HTTP_400_BAD_REQUEST)
|
||
2 ({"message": "<_Internal Server Error>",
|
||
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||
```
|
||
---------
|
||
|
||
### 6. Edit
|
||
**URL:**
|
||
...wells/<well_id>/edit/
|
||
|
||
**Method**:
|
||
PUT
|
||
|
||
**Input**:
|
||
1. URL: well id
|
||
2. Header:
|
||
```python
|
||
{"Authorization" : f"Bearer {access_token}" }
|
||
```
|
||
3. Request body:
|
||
```python
|
||
{
|
||
"license_code": "<some_data>",
|
||
"representor": "<user_id>",
|
||
"subscriptionـcode": "<some_data>",
|
||
}
|
||
```
|
||
|
||
**Output:**
|
||
1. OK:
|
||
```python
|
||
({"data": "<serializer.data>"},
|
||
status=status.HTTP_200_OK)
|
||
```
|
||
2. Errors:
|
||
```python
|
||
|
||
1. ({"message": "Not Found"},
|
||
status=status.HTTP_404_NOT_FOUND)
|
||
|
||
2. ({"message":serializer.errors},
|
||
status=status.HTTP_400_BAD_REQUEST)
|
||
|
||
2 ({"message": "<_Internal Server Error>",
|
||
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||
```
|
||
---------
|