100 Words in 100 Days 10/100: An evolving API (10)

less than 1 minute read

In last article, the structure of the code is not adequate for 2 developers to separate their work and be focus. And lack of focus is the number 1 productivity destroyer. So CTO Lucy have started to look for ways to decouple the API.She found a technique to hide all discount_code related logic into a single function.

class Api::ServiceRequestController
    # ... some other Concerns
    include ServiceRequestParamsSanitizer
    include DiscountCode
    # ... some other Concerns
    # POST v10/service_request
    def place_request_of_service_v13
            sanitized_service_request_params = sanitize(service_request_params)
            @service_request = ServiceRequest.new(sanitized_service_request_params)

            reduced_price = DiscountCode.process(@service_request.customer, @service_request.discount_code)
            # Some other operations that are unrelated to service_request

            render(json: { id: @service_request.id }, status: :created)

So by doing this Lucy and Bob who is responsible for service_request and discount_code can work independently for now.

Next let’s fast forward into a few months later, when the company take off and separate their discount_code with a separate service.