CodeBlanks Logo Icon CodeBlanks

Integration

Build the working app by combining all parts.

Summary - Weather app

In this project you combined all parts of a weather app: the data model, API response type, transform function, and display function. Each part carries its own responsibility and together they form a working application. The model represents data, the API type the external source, the transform the bridge, and formatting the output.

interface Weather { city: string; temperature: number; }
function transform(r: ApiResponse): Weather { ... }
function format(w: Weather): string { ... }

Final assembly

In the final assembly, all parts merge in a single flow: raw data of type ApiResponse is received, transformed to the Weather model with transform, then the text to show the user is produced with format. This flow keeps external and internal data separate and makes maintenance easier.

Practice Working weather app

Define ApiYanit and Hava interfaces: both contain sehir: string and sicaklik: number. The donustur function should be (y: ApiYanit): Hava and return { sehir: y.sehir, sicaklik: y.sicaklik }. The formatla function should be (h: Hava): string and return h.sehir + " " + h.sicaklik + "C". Create an ApiYanit object named yanit with { sehir: "Antalya", sicaklik: 30 }. Assign the result of donustur(yanit) to hava and print formatla(hava) with console.log.

Starter code

index.ts
// ApiYanit ve Hava interface tanımla
// donustur ve formatla fonksiyonları yaz
// yanit nesnesi oluştur
// donustur ile hava'ya çevir, formatla ile yazdır

Sample solution

index.ts
interface ApiYanit { sehir: string; sicaklik: number; }
interface Hava { sehir: string; sicaklik: number; }
function donustur(y: ApiYanit): Hava {
  return { sehir: y.sehir, sicaklik: y.sicaklik };
}
function formatla(h: Hava): string {
  return h.sehir + " " + h.sicaklik + "C";
}
const yanit: ApiYanit = { sehir: "Antalya", sicaklik: 30 };
const hava = donustur(yanit);
console.log(formatla(hava));

Expected output

Antalya 30C

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What is the correct flow during integration?

  • First define interface, then nothing
  • First format, then API call
  • First format, then transform
  • Get API data, transform, format Correct answer

Explanation: Correct flow: API data is received, transformed to the internal model with donustur, then displayed with formatla.

2 Transform function call

Question
const hava = ____(yanit);
Answer
const hava = donustur(yanit);

Explanation: To convert raw API data to the internal model, the donustur function is called; formatla is only for display.

3 Integration parts

Term Meaning
ApiYanit API data type
donustur Transform step
formatla Display step
yanit Raw API data

All lessons in Intermediate