diff --git a/README.md b/README.md index 3295215b969b3205e4740a806c168130ec5c45d0..677c3ee132a54300c689a098a0228687ebc09b35 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ Henter informasjon om et land basert på en 2-bokstavs landkode (ISO 3166-2). ```sh http://localhost:8080/countryinfo/v1/info/{country_code}{?limit=10} ``` +* limit er en valgfri parameter som gir en begrenisng på antall byer som vises med valgt land (Default er 10 stykker) * Metode: GET * Eksempel: http://localhost:8080/countryinfo/v1/info/NO?limit=4 @@ -40,6 +41,7 @@ Hente populasjonsdata om et land basert på en 2-bokstavs landkode (ISO 3166-2). ```sh http://localhost:8080/countryinfo/v1/population/{country_code}{?startyear-endYear} ``` +* startYear-endYear er en valfri parameter som gir begreninger på spesifikke år du får populasjonsdata fra (Default er alle tilgjengelige år) * Metode: GET * Eksempel: http://localhost:8080/population/NO?limit=2010-2015 diff --git a/handelers/homeHandler.go b/handelers/homeHandler.go index be20d268b1d8d3a2796ec450d3d8b69abe2262c7..4976d275c0b486345f817306eefaca3df479f999 100644 --- a/handelers/homeHandler.go +++ b/handelers/homeHandler.go @@ -10,17 +10,22 @@ import ( func HomeHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") response := map[string]interface{}{ - "WELCOME": "Welcome to the Country Info API", + WELCOME: WELCOME_MESSAGE, "endpoints": map[string]interface{}{ "Get Country Info": map[string]string{ "Description": "Get country details including cities, population, and more.", - "URL Format": "http://localhost:8080/countryinfo/v1/info/{country_code}{?limit=10}", + "URL Format": "http://localhost:8080/countryinfo/v1/info/{ISO_3166-2_country_code}{?limit=10}", "Example": "http://localhost:8080/countryinfo/v1/info/NO?cities=5", }, "Get status info" : map[string]string{ "Description" : "Get information about the API statuses", "URL" : "http://localhost:8080/status/", }, + "Get population info" : map[string]string{ + "Description" : "Get information about countries and their population", + "URL" : "http://localhost:8080/countryinfo/v1/population/{ISO_3166-2_country_code}{?startYear-endYear}", + "Example": "http://localhost:8080/countryinfo/v1/population/NO?2010-2015}", + }, }, } diff --git a/handelers/konstanter.go b/handelers/konstanter.go index 4afe3bec8a7ec74c518f3526d4ad53bf83d4b413..5f9e9a644cbe176412767be5cb5a4b9fa6bca03d 100644 --- a/handelers/konstanter.go +++ b/handelers/konstanter.go @@ -10,4 +10,8 @@ const SLASH_DEFAULT = "/" //ERRORS //Terminal info -const RUNNING_ON_PORT = "" \ No newline at end of file +const RUNNING_ON_PORT = "" + +//User information +const WELCOME = "WELCOME" +const WELCOME_MESSAGE = "Welcome to the Country Info API" \ No newline at end of file diff --git a/main.go b/main.go index d1d47183c8e3078ecba9331c8dff6af98dfd33e0..364c129eaf6490e0ed6eb5c9bbf9bcc9d0f51bc2 100644 --- a/main.go +++ b/main.go @@ -19,8 +19,8 @@ func main() { http.HandleFunc(handelers.INFO_DEFAULT, handelers.CountryInfoHandler) http.HandleFunc(handelers.POPULATION_DEFAULT, handelers.PopulationHandler) - if err := http.ListenAndServe(":8080", nil); err != nil { fmt.Printf("Server failed to start: %s\n", err) } -} \ No newline at end of file +} +