🔌 Como Criar Novos Endpoints - ecosif-compliance

📋 Visão Geral

Este guia explica como criar novos endpoints REST no serviço ecosif-compliance.


📝 Passo a Passo

1. Criar Service (se necessário)

# app/service/novo_service.py
from flask import Response
import json
import http

def nova_funcionalidade(param1, param2):
    # Lógica aqui
    result = {"status": "ok"}
    headers = {'Content-Type': 'application/json'}
    return Response(json.dumps(result), headers=headers, status=http.HTTPStatus.OK)

2. Adicionar Endpoint em starter.py

# app/starter.py
from service import novo_service

@api.route('/api/compliance/novo-endpoint')
class NovoEndpoint(Resource):
    @cross_origin()
    def get(self):
        try:
            response = novo_service.nova_funcionalidade(...)
            return response
        except CustomHttpException:
            raise
        except Exception as e:
            logger.error(f"Erro: {str(e)}", exc_info=True)
            raise InternalServerErrorException(f"Erro interno: {str(e)}")

Última Atualização: 2025-12-01