handleGet method

Future<Response> handleGet(
  1. Request request
)

Handles Get http requisitions. Requires a http Request (from the Shelf package).

Implementation

Future<Response> handleGet(Request request) async {
  if (!middlewareJwt(request)) {
    return Response.forbidden(jsonEncode({'error': 'middlewareJwt'}));
  }

  try {
    final dynamic seg = await getSegment(request);

    if (seg == null) {
      return Response.notFound(jsonEncode({'error': 'Not found'}));
    } else {
      return Response.ok(
        jsonEncode(seg),
        headers: {'content-type': 'application/json'},
      );
    }
  } catch (e) {
    return Response.notFound(jsonEncode({'error': 'Internal Error. $e'}));
  }
}