base rest api endpoints.
This commit is contained in:
parent
2d471ecf9d
commit
45f92fb4c7
10 changed files with 208 additions and 2 deletions
40
moto/apigateway/responses.py
Normal file
40
moto/apigateway/responses.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import json
|
||||
|
||||
from moto.core.responses import BaseResponse
|
||||
from .models import apigateway_backends
|
||||
|
||||
|
||||
class APIGatewayResponse(BaseResponse):
|
||||
|
||||
def _get_param(self, key):
|
||||
return json.loads(self.body).get(key)
|
||||
|
||||
@property
|
||||
def backend(self):
|
||||
return apigateway_backends[self.region]
|
||||
|
||||
def restapis(self, request, full_url, headers):
|
||||
self.setup_class(request, full_url, headers)
|
||||
|
||||
if self.method == 'GET':
|
||||
apis = self.backend.list_apis()
|
||||
return 200, headers, json.dumps({"item": [
|
||||
api.to_dict() for api in apis
|
||||
]})
|
||||
elif self.method == 'POST':
|
||||
name = self._get_param('name')
|
||||
description = self._get_param('description')
|
||||
rest_api = self.backend.create_rest_api(name, description)
|
||||
return 200, headers, json.dumps(rest_api.to_dict())
|
||||
|
||||
def restapis_individual(self, request, full_url, headers):
|
||||
self.setup_class(request, full_url, headers)
|
||||
function_id = self.path.split("/")[-1]
|
||||
if self.method == 'GET':
|
||||
rest_api = self.backend.get_rest_api(function_id)
|
||||
return 200, headers, json.dumps(rest_api.to_dict())
|
||||
elif self.method == 'DELETE':
|
||||
rest_api = self.backend.delete_rest_api(function_id)
|
||||
return 200, headers, json.dumps(rest_api.to_dict())
|
||||
Loading…
Add table
Add a link
Reference in a new issue