input: Write a python function to define Django URL patterns and handle GET and POST requests.
  assert handle_request('GET') == 'GET request received at /api/'
  assert handle_request('POST') == 'POST request received at /api/'
output: from django.urls import path
  from django.http import JsonResponse
  from django.views import View
  
  class ApiView(View):
      def get(self, request):
          return JsonResponse({'message': 'GET request received at /api/'})
      
      def post(self, request):
          return JsonResponse({'message': 'POST request received at /api/'})
  
  urlpatterns = [
      path('api/', ApiView.as_view(), name='api')
  ]
  
  def handle_request(method):
      from django.test import RequestFactory
      factory = RequestFactory()
      request = factory.get('/api/') if method == 'GET' else factory.post('/api/')
      response = ApiView.as_view()(request)
      return response.json()['message']