Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 35 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[![Build Status](https://github.com/rgdevment/RetrieveCountriesAPI/actions/workflows/main.yml/badge.svg)](https://github.com/rgdevment/RetrieveCountriesAPI/actions/workflows/main.yml)
[![Coverage](https://rgdevment.github.io/RetrieveCountriesAPI/badges/jacoco.svg)](https://rgdevment.github.io/RetrieveCountriesAPI) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=rgdevment_RetrieveCountriesAPI&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=rgdevment_RetrieveCountriesAPI)
[![Coverage](https://rgdevment.github.io/RetrieveCountriesAPI/badges/jacoco.svg)](https://rgdevment.github.io/RetrieveCountriesAPI)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=rgdevment_RetrieveCountriesAPI&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=rgdevment_RetrieveCountriesAPI)

# RetrieveCountriesAPI

Retrieve Countries API is an open-source REST API licensed under MIT that allows you to query data about countries,
RetrieveCountriesAPI is an open-source REST API licensed under MIT that allows you to query data about countries,
cities, and other relevant information worldwide. This API is continuously developing and growing.

## Documentation
Expand All @@ -13,44 +14,54 @@ cities, and other relevant information worldwide. This API is continuously devel

## Example Usage

### Get All Countries

#### GET /v1/countries

Retrieves all country data with an option to exclude cities.

**Parameters:**

- `includeCities` (optional): boolean
- `includeStates` (optional): boolean

include states
A simple request:

```sh
curl -X GET "https://countries.restapi.cl/v1/all?includeStates=true"
curl -X GET "https://countries.restapi.cl/v1/all"
```

include cities
To get a specific country:

```sh
curl -X GET "https://countries.restapi.cl/v1/all?includeCities=true"
curl -X GET "https://countries.restapi.cl/v1/chile"
```

include states and cities
If you need all regions with their states:

```sh
curl -X GET "https://countries.restapi.cl/v1/all?includeCities=true&includeStates=true"
curl -X GET "https://countries.restapi.cl/v1/region/americas"
```

or single request
In addition to the above, you can also obtain additional information with the following **parameters**

```sh
curl -X GET "https://countries.restapi.cl/v1/v1/all"
```
- `includeCities` (optional): boolean
- `includeStates` (optional): boolean

For more information and other endpoints, please refer to the Postman API Documentation or Swagger Documentation.

## License

This project is licensed under the [MIT License](https://choosealicense.com/licenses/mit/). See
the [LICENSE](LICENSE.md) file for more details.
the [LICENSE](LICENSE.md) file for more details.

## 🌟 **Thank you for using this API!**

Our API is a **public service**, **freely available** for use, and it's **open-source**.

We have **limited resources**. To help us efficiently serve everyone, please **cache requests** in your application.
This will reduce unnecessary resource consumption.

Please maintain **good practices and behavior** to ensure we can continue providing this service **freely and openly**
to all who need it.

---

## 🌟 **¡Gracias por utilizar esta API!**

Nuestra API es un **servicio público**, **disponible de forma gratuita** para su uso, y es **de código abierto**.

Contamos con **recursos limitados**. Para ayudarnos a servir eficientemente a todos, por favor **almacene en caché las
solicitudes** en su aplicación. Esto reducirá el consumo innecesario de recursos.

Por favor, mantenga **buenas prácticas y comportamiento** para asegurar que podamos continuar proporcionando este
servicio **libre y abiertamente** para todos aquellos que lo necesiten.
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ public ResponseEntity<MappingJacksonValue> getCountries(@RequestParam(required =
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Country.class)))
@ApiResponse(responseCode = "204", description = "No content", content = @Content)
@GetMapping("/{name}")
public ResponseEntity<MappingJacksonValue> getCountryByName(@PathVariable String name,
@RequestParam(required = false) Boolean includeCities,
@RequestParam(required = false) Boolean includeStates) {
public ResponseEntity<MappingJacksonValue> getCountryByName(
@PathVariable String name,
@RequestParam(required = false, defaultValue = "true") Boolean includeCities,
@RequestParam(required = false) Boolean includeStates) {
Country country = this.service.findByName(name);
return getMappingJacksonValueResponseEntity(includeCities, includeStates, country);
}
Expand All @@ -63,7 +64,8 @@ public ResponseEntity<MappingJacksonValue> getCountryByName(@PathVariable String
@ApiResponse(responseCode = "204", description = "No content", content = @Content)
@GetMapping("/capital/{name}")
public ResponseEntity<MappingJacksonValue> getCountryByCapital(
@PathVariable String name, @RequestParam(required = false) Boolean includeCities,
@PathVariable String name,
@RequestParam(required = false, defaultValue = "true") Boolean includeCities,
@RequestParam(required = false) Boolean includeStates) {
Country country = this.service.findByCapital(name);
return getMappingJacksonValueResponseEntity(includeCities, includeStates, country);
Expand All @@ -77,8 +79,9 @@ public ResponseEntity<MappingJacksonValue> getCountryByCapital(
@ApiResponse(responseCode = "204", description = "No content", content = @Content)
@GetMapping("/region/{region}")
public ResponseEntity<MappingJacksonValue> getCountriesByRegion(
@PathVariable String region, @RequestParam(required = false) Boolean includeCities,
@RequestParam(required = false) Boolean includeStates) {
@PathVariable String region,
@RequestParam(required = false) Boolean includeCities,
@RequestParam(required = false, defaultValue = "true") Boolean includeStates) {
List<Country> countries = service.findByRegion(region);
return getMappingJacksonValueResponseListEntity(includeCities, includeStates, countries);
}
Expand All @@ -91,8 +94,9 @@ public ResponseEntity<MappingJacksonValue> getCountriesByRegion(
@ApiResponse(responseCode = "204", description = "No content", content = @Content)
@GetMapping("/subregion/{subregion}")
public ResponseEntity<MappingJacksonValue> getCountriesBySubregion(
@PathVariable String subregion, @RequestParam(required = false) Boolean includeCities,
@RequestParam(required = false) Boolean includeStates) {
@PathVariable String subregion,
@RequestParam(required = false) Boolean includeCities,
@RequestParam(required = false, defaultValue = "true") Boolean includeStates) {
List<Country> countries = service.findBySubregion(subregion);
return getMappingJacksonValueResponseListEntity(includeCities, includeStates, countries);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ void testGetCountryByName() throws Exception {
.andExpect(jsonPath("$.latitude").value(country.getLatitude()))
.andExpect(jsonPath("$.longitude").value(country.getLongitude()))
.andExpect(jsonPath("$.currency").exists())
.andExpect(jsonPath("$.cities").doesNotExist())
.andExpect(jsonPath("$.cities").exists())
.andExpect(jsonPath("$.states").doesNotExist())
.andExpect(jsonPath("$.flags").exists());

Expand Down Expand Up @@ -279,7 +279,7 @@ void testGetCountryByCapital() throws Exception {
.andExpect(jsonPath("$.latitude").value(country.getLatitude()))
.andExpect(jsonPath("$.longitude").value(country.getLongitude()))
.andExpect(jsonPath("$.currency").exists())
.andExpect(jsonPath("$.cities").doesNotExist())
.andExpect(jsonPath("$.cities").exists())
.andExpect(jsonPath("$.states").doesNotExist())
.andExpect(jsonPath("$.flags").exists());

Expand Down Expand Up @@ -337,7 +337,7 @@ void testGetCountryByRegion() throws Exception {
.andExpect(jsonPath("$[0].longitude").value(countries.getFirst().getLongitude()))
.andExpect(jsonPath("$[0].currency").exists())
.andExpect(jsonPath("$[0].cities").doesNotExist())
.andExpect(jsonPath("$[0].states").doesNotExist())
.andExpect(jsonPath("$[0].states").exists())
.andExpect(jsonPath("$[0].flags").exists());

verify(service, times(1)).findByRegion(countries.getFirst().getRegion());
Expand Down Expand Up @@ -366,7 +366,7 @@ void testGetCountryBySubRegion() throws Exception {
.andExpect(jsonPath("$[0].longitude").value(countries.getFirst().getLongitude()))
.andExpect(jsonPath("$[0].currency").exists())
.andExpect(jsonPath("$[0].cities").doesNotExist())
.andExpect(jsonPath("$[0].states").doesNotExist())
.andExpect(jsonPath("$[0].states").exists())
.andExpect(jsonPath("$[0].flags").exists());

verify(service, times(1)).findBySubregion(countries.getFirst().getSubregion());
Expand Down