If you take
$$f(z) = \frac{e^{iz}}{1+z^2}$$
and apply the residue theorem over the path $\Gamma = \gamma_1 + \gamma_2$:
$\Gamma$" />
You have as follow:
$$\frac{1}{2\pi i}\int_{\Gamma} f(z)dz = \text{Res}(f,i)$$
'cause, of the two poles of $f(z)$, only $i$ is inside $\Gamma$. So, $\int_{\Gamma} f(z)dz = \int_{\gamma_1} f(z)dz + \int_{\gamma_2} f(z)dz$. Let's do it one by one:
$$\int_{\gamma_1} f(z)dz = \int_{\gamma_1} \frac{e^{iz}}{1+z^2}dz = \int_{-R}^{R} \frac{e^{it}}{1+t^2}dt$$
because we have parametrized $\gamma_1$ as $\gamma_1(t) = t$, for $t\in[-R,R]$ and $dz = dt$.
$$\int_{-R}^{R} \frac{e^{it}}{1+t^2}dt = \int_{-R}^{R} \frac{\cos(t) + i\sin(t)}{1+t^2}dt = \int_{-R}^{R} \frac{\cos(t)}{1+t^2}dt + i\int_{-R}^{R} \frac{\sin(t)}{1+t^2}dt$$
But the second one of this two integrals is zero, cause $\frac{\sin(t)}{1+t^2}$ is an odd function. Allright, let's take care of the integral
$$
\int_{\gamma_2} f(z)dz = \int_{0}^{\pi} \frac{e^{iRe^{it}}}{1 + R^2e^{i2t}}iRe^{it} dt
$$
'cause, now, $\gamma_2 = e^{it}$ for $t \in [0,\pi]$, so $z=Re^{it}$ and $dz = iRe^{it}dt$. Then, we have:
$$
\int_{0}^{\pi} \frac{e^{iRe^{it}}}{1 + R^2e^{i2t}}iRe^{it} dt = \int_{0}^{\pi} \frac{e^{iR(\cos(t)+i\sin(t))}}{1 + R^2e^{i2t}}iRe^{it}dt =\\
\int_{0}^{\pi} \frac{e^{iR\cos(t)} e^{-R\sin(t)}}{1 + R^2e^{i2t}}iRe^{it}dt \leq \int_{0}^{\pi} \left|\frac{e^{iR\cos(t)} e^{-R\sin(t)}}{1 + R^2e^{i2t}}iRe^{it}dt\right| = \int_{0}^{\pi} \frac{R}{1 + R^2e^{i2t}}e^{-R\sin(t)}dt
$$
and,
$$
\lim_{R\rightarrow +\infty} \int_{0}^{\pi} \frac{R}{1 + R^2e^{i2t}}e^{-R\sin(t)}dt = 0
$$
So, summing up, we have
$$
\int_{\Gamma} f(z)dz = \int_{-R}^{R} \frac{\cos(t)}{1+t^2}dt
$$
and, trivially,
$$
\lim_{R\rightarrow +\infty} \int_{-R}^{R} \frac{\cos(t)}{1+t^2}dt = \int_{-\infty}^{\infty} \frac{\cos(t)}{1+t^2}dt
$$
just, what we want to know. The computing of Res($f, i$) it's simple 'cause $i$ is a pole of degree 1, so you just have to derive the denominator and evaluate all in $z=i$, And finally, for the residue theorem, we have, for $R\rightarrow +\infty$:
$$
\frac{1}{2\pi i} \int_{\Gamma} f(z)dz = \frac{1}{2\pi i} \int_{-\infty}^{\infty} \frac{\cos(t)}{1+t^2}dt = Res(f, i) = \frac{e^{it}}{(1+z^2)'}\Bigg\rvert_{z=i} = \frac{e^{it}}{2z}\Bigg\rvert_{z=i} =\frac{e^{-1}}{2i}\\
\longrightarrow \int_{-\infty}^{\infty} \frac{\cos(t)}{1+t^2}dt = \frac{\pi}{e}
$$