🍻 POST-request m/ payload mot backend lagt til + jackson (heehee)
Co-authored-by: Amalie Erdal Mansåker <amalie.erdal.mansaker@nav.no> Co-authored-by: Markus A. R. Johansen <markus.aleksander.rakil.johansen@nav.no>
This commit is contained in:
		
							parent
							
								
									a8446b6b73
								
							
						
					
					
						commit
						fdf54063c2
					
				
					 4 changed files with 54 additions and 0 deletions
				
			
		
							
								
								
									
										10
									
								
								backend/src/main/kotlin/no/nav/helse/sprik/Test.kt
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								backend/src/main/kotlin/no/nav/helse/sprik/Test.kt
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,10 @@ | |||
| package no.nav.helse.sprik | ||||
| 
 | ||||
| class Test ( | ||||
|     var ord: String, | ||||
|     var tall: Int | ||||
| ) { | ||||
|     override fun toString(): String { | ||||
|         return "Test(ord='$ord', tall=$tall)" | ||||
|     } | ||||
| } | ||||
|  | @ -1,19 +1,39 @@ | |||
| package no.nav.helse.sprik.plugins | ||||
| 
 | ||||
| import com.fasterxml.jackson.databind.SerializationFeature | ||||
| import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule | ||||
| import io.ktor.http.* | ||||
| import io.ktor.serialization.jackson.* | ||||
| import io.ktor.server.routing.* | ||||
| import io.ktor.server.response.* | ||||
| import io.ktor.server.application.* | ||||
| import io.ktor.server.plugins.contentnegotiation.* | ||||
| import io.ktor.server.plugins.cors.routing.* | ||||
| import io.ktor.server.request.* | ||||
| import no.nav.helse.sprik.Test | ||||
| 
 | ||||
| fun Application.configureRouting() { | ||||
|     install(CORS) { | ||||
|         anyHost() | ||||
|         allowMethod(HttpMethod.Get) | ||||
|         allowMethod(HttpMethod.Post) | ||||
|         //allowHeader(HttpHeaders.AccessControlAllowOrigin) | ||||
|         allowNonSimpleContentTypes = true | ||||
|     } | ||||
|     install(ContentNegotiation) { | ||||
|         jackson { | ||||
|             disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) | ||||
|             registerModule(JavaTimeModule()) | ||||
|         } | ||||
|     } | ||||
|     routing { | ||||
|         get("/") { | ||||
|             call.respondText("Hello World!") | ||||
|         } | ||||
|         post("/test") { | ||||
|             val test = call.receive<Test>() | ||||
|             println(test) | ||||
|             //call.respondText(test.toString()) | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  |  | |||
		Reference in a new issue
	
	 Sindre Kjelsrud
						Sindre Kjelsrud