I consider the complexification $$f(z)=\frac{e^{iz}}{e^z+e^{-z}}$$
Poles of $f$: $\text{Denominator}=e^{-z}(e^{2z}+1)=0\Rightarrow e^{2z}=-1=e^{i(\pi + 2\pi k)}\Rightarrow z=\frac{i\pi(1+ 2k)}{2}$, so the poles lie on the $y-$axis. Since there are infinitely many of them, one contour I would like to use is a semicircle of infinite radius, but I am not sure if I am allowed to use such a contour when applying the residue theorem. Another contour that comes to mind is the boundary of a rectangle with vertices $(-R,0),(R,0),(R,\frac{\pi i}{4}), (-R,\frac{\pi i}{4})$, but 3 of these integrals seem difficult to calculate. I am not sure if the integrals along the opposite vertical sides will cancel each other out. How can I proceed? I have more experience with integrating along circular arcs than lines.
Much easier to use a rectangular contour $C$, in this case, vertices at $-R$, $R$, $R+i \pi$, $-R + i \pi$. Then consider
$$\frac12 \oint_C dz \frac{\cos{z}}{\cosh{z}} $$
which is equal to
$$\frac12 \int_{-R}^R dx \frac{\cos{x}}{\cosh{x}} + i \frac12\int_0^\pi dy \frac{\cos{(R+i y)}}{\cosh{(R+i y)}} \\ + \frac12 \int_R^{-R} dx \frac{\cos{(x+i \pi)}}{\cosh{(x+i \pi)}} + i \frac12 \int_{\pi}^0 dy \frac{\cos{(-R+i y)}}{\cosh{(-R+i y)}}$$
Now,
$$\cosh{(x + i \pi)} = -\cosh{x}$$ $$\cos{(x+i \pi)} = \cosh{\pi} \cos{x} - i \sinh{\pi} \sin{x} $$
We take the limit as $R \to \infty$. In this limit, the second and fourth integrals vanish and the contour integral is equal to
$$\frac{1+\cosh{\pi}}{2} \int_{-\infty}^{\infty} dx \frac{\cos{x}}{\cosh{x}} - i \frac{\sinh{\pi}}{2} \int_{-\infty}^{\infty} dx \frac{\sin{x}}{\cosh{x}}$$
The imaginary part is zero because the corresponding integral is zero.
By the residue theorem, the contour integral is equal to $i 2 \pi$ times the residue of the integrand at the pole $z=i \pi/2$, or
$$i 2 \pi \frac12 \frac{\cosh{(\pi/2)}}{i \sin{(\pi/2)}} = \pi \cosh{(\pi/2)} $$
Thus,
$$\int_{-\infty}^{\infty} dx \frac{\cos{x}}{e^x+e^{-x}} = \frac{\pi \cosh{(\pi/2)}}{1+\cosh{\pi}} = \frac{\pi}{2 \cosh{(\pi/2)}}$$