r"""
        Used to create a node in the database of type 'cls' in response to a POST request. create_resource should only \
        be invoked on a resource when the client specifies a POST request.

        :param request_json: a dictionary formatted according to the specification at \
        http://jsonapi.org/format/#crud-creating
        :return: An HTTP response object in accordance with the same specification

def create_resource(cls, request_json):
        r"""
        Used to create a node in the database of type 'cls' in response to a POST request. create_resource should only \
        be invoked on a resource when the client specifies a POST request.

        :param request_json: a dictionary formatted according to the specification at \
        http://jsonapi.org/format/#crud-creating
        :return: An HTTP response object in accordance with the same specification
        """
        response = dict()
        new_resource, location = None, None
        try:
            data = request_json['data']
            if data['type'] != cls.__type__:
                raise WrongTypeError('type must match the type of the resource being created.')

            attributes = data.get('attributes')
            if attributes:
                for x in attributes.keys():
                    if x in cls.dates:
                        dt = datetime.strptime(attributes[x], '%Y-%m-%d')
                        attributes[x] = dt

                new_resource = cls(**attributes)
                new_resource.save()

                enum_keys = new_resource.enums.keys()
                for key in attributes.keys():
                    if key in enum_keys:
                        if attributes[key] in new_resource.enums[key]:
                            setattr(new_resource, key, attributes[key])
                        else:
                            raise EnumeratedTypeError
                    else:
                        setattr(new_resource, key, attributes[key])
                    new_resource.save()

                for r in new_resource.hashed:
                    unhashed = getattr(new_resource, r)
                    if unhashed:
                        setattr(new_resource, r, hashlib.sha256(unhashed).hexdigest())
                        new_resource.save()

            relationships = data.get('relationships')
            if relationships:
                for relation_name in relationships.keys():
                    relations = relationships.get(relation_name)
                    if relations:
                        relations = relations['data']
                        if isinstance(relations, list):
                            for relation in relations:
                                the_type = relation['type']  # must translate type to cls
                                the_id = relation['id']
                                the_class = cls.get_class_from_type(the_type)
                                new_resources_relation = the_class.nodes.get(id=the_id, active=True)
                                meta = relation.get('meta')
                                eval('new_resource.{relation_name}.connect(new_resources_relation, meta)'.format(
                                    relation_name=relation_name)
                                )
                                new_resource.save()
                        else:
                            relation = relations
                            the_type = relation['type']
                            the_id = relation['id']
                            the_class = cls.get_class_from_type(the_type)
                            new_resources_relation = the_class.nodes.get(id=the_id, active=True)
                            meta = relation.get('meta')
                            eval('new_resource.{relation_name}.connect(new_resources_relation, meta)'.format(
                                relation_name=relation_name)
                            )
                            new_resource.save()

            response['data'] = new_resource.get_resource_object()
            response['links'] = {'self': new_resource.get_self_link()}
            status_code = http_error_codes.CREATED
            location = new_resource.get_self_link()

            r = make_response(jsonify(response))
            r.headers['Content-Type'] = "application/vnd.api+json; charset=utf-8"
            if location and new_resource:
                r.headers['Location'] = location

            r.status_code = status_code

        except UniqueProperty:
            r = application_codes.error_response([application_codes.UNIQUE_KEY_VIOLATION])
            try:
                new_resource.delete()
            except:
                pass

        except DoesNotExist:
            r = application_codes.error_response([application_codes.RESOURCE_NOT_FOUND])
            try:
                new_resource.delete()
            except:
                pass

        except WrongTypeError as e:
            r = application_codes.error_response([application_codes.WRONG_TYPE_VIOLATION])
            try:
                new_resource.delete()
            except:
                pass

        except KeyError as e:
            r = application_codes.error_response([application_codes.BAD_FORMAT_VIOLATION])
            print e
            try:
                new_resource.delete()
            except:
                pass

        except EnumeratedTypeError:
            r = application_codes.error_response([application_codes.ENUMERATED_TYPE_VIOLATION])
            try:
                new_resource.delete()
            except:
                pass

        except ParameterMissing:
            r = application_codes.error_response([application_codes.BAD_PARAMETER_VIOLATION])
            try:
                new_resource.delete()
            except:
                pass

        return r