• Documentation of Corr Tool
    • Installation
    • Journey Programming Language
      • Data Types
      • Expressions
      • Templates
      • Statements
        • Rest Operations
        • Service Virtualisation
          • Endpoint Definition
          • Tag Server Example

Tag Server Example

Below is an example of a Simple Dynamic Tag Server that maintains the state of tags in the tags variable.

05_TagServer.journey

`05_TagServer`(){
    let next_id = 1
    let tags = object []
    listen on 8720 with {
        //Get Tag By Id
        on get with url text `/tag/<%id:PositiveInteger%>` {
            //Default Response
            let bd = "Not Found"
            let code = 404
            //Find Tags
            tags.for(item)=>{
                if item.id == id {
                    let bd = item
                    let code = 200
                }
            }
            respond with status code and body bd //Respond
        }
        //Get All Tags
        on get with url text `/tag` {
            respond with body tags //Respond
        }
        //Create New Tag
        on post with url text `/tag`  matching request body object { "name" : name }
        {
            let tag = object {"id" : next_id, "name":name}
            tags.push(tag)
            let next_id = next_id + 1
            respond with body tag //Respond
        }
    }
}