Giter Club home page Giter Club logo

hmrc.customs-api-common's Introduction

Customs API Common

Download

A play module library that contains common infrastructure code for Customs micro services.

It also has a DynamicStubbingService and routes to enable the switching of connector URLs from real to stubbed services.

Migration of existing micro services to use this library

SBT dependencies

Add a dependency to this library in AppDependencies.scala

val customsApiCommon = "uk.gov.hmrc" %% "customs-api-common" % customsApiCommonVersion

Add this in build.sbt

val compileDependencies = Seq(..., customsApiCommon)

SBT Test Dependencies

When adding test dependencies add the following to AppDependencies.scala

val customsApiCommonTests = "uk.gov.hmrc" %% "customs-api-common" % customsApiCommonVersion % testScope classifier "tests"

And add this to build.sbt

val testDependencies = Seq(..., customsApiCommonTests)

application.conf

Make sure you have the following entries

application.logger.name="YOUR_APP_LOGGER_NAME"

microservice {
  ...      
  services {
    ...
  }
}
  
# Play Modules
# ~~~~
# Additional play modules can be added here
play.modules.enabled += "uk.gov.hmrc.customs.api.common.CustomsApiCommonModule"

play.http.errorHandler = "uk.gov.hmrc.customs.api.common.config.CustomsErrorHandler"

For more details on configuration see here.

##To add Dynamic Service Configuration Add configuration in your 'application.conf', additional environments are added to the service. Dynamic service configuration may be used for stubs as well as other environments

services {
  your-service {
    host = some.host
    port = 80
    bearer-token = ...
    context = /osb/submitdeclaration/1.0.0
    
    environment {
        host = other.host
        port = 80
        bearer-token = ...
        context = /osb/submitdeclaration/1.0.0
    }
    
    stub {
        host = localhost
        port = 9477
        bearer-token = ...
        context = /submitdeclaration
    }
  }
 }

Create test only routes file testOnlyDoNotUseInAppConf.routes with contents

->        /test-only/service               dynamicservice.Routes

->        /                                prod.Routes

In your connector inject the ServiceConfigProvider

@Singleton
class MyConnector @Inject()(.... // other dependencies
                            configProvider: ServiceConfigProvider)

Call the service to get the dynamically switched service configuration and use it in the HTTP method

...
val serviceConfig = configProvider.getConfg("your-service")
ws.url(serviceConfig.url).withHeaders(headers: _*)
...

You will need to run the microservice with the -Dapplication.router=testOnlyDoNotUseInAppConf.Routes JVM parameter set.

To switch service configuration (replace 'environment' property in the body with the name of the configured environment you would like to point the service to):

POST /test-only/service/:service-name/configuration

Headers:
    Content-Type: application/json
    
Body: { "environment": "stub" }

Use the environment name 'default' to switch back to the root configuration

To view the current configuration for a service:

GET /test-only/service/:service-name

Example response:

{
  "service": "your-service",
  "environment": "default",
  "url": "http://some.host:80/osb/submitdeclaration/1.0.0",
  "bearerToken": "..."
}

License

This code is open source software licensed under the Apache 2.0 License.

hmrc.customs-api-common's People

Contributors

paulblakehmrc avatar mattclark-zerogravit avatar glidester avatar rashadmughal avatar hmrc-web-operations avatar googley42 avatar usmanshabbir avatar tomasz-rosiek avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.