Show that $e^{ix}=\cos(x)+i\sin(x)$ using the Fourier Series only As stated in the title.
Any arbitrary function can be expressed as
$$f(x)=\frac{a_0}{2}+\sum^{\infty}_{n=1}(a_n\cos(nx)+b_n\sin(nx)) \tag{1}$$
where
$$a_n=\frac{1}{\pi}\int_{-\pi}^{\pi}f(x)\cos(nx)dx \tag{2}$$
$$b_n=\frac{1}{\pi}\int_{-\pi}^{\pi}f(x)\sin(nx)dx \tag{3}$$

I am trying to show that (1)-(3) are consistent with $f(x)=e^{ix}=\cos(x)+i\sin(x)$.
However, for $a_n=\frac{1}{\pi}\int^{\pi}_{-\pi}e^{ix}\cos(nx)dx$ I got $a_n=0$, similarly, $b_n=0$.
What's gone wrong? Are the integral limits $\int_{-\pi}^{\pi}$ not valid in general, does it require modifications for non-periodic functions?
 A: Let's try this definition: $f(x) = e^{ix}$ is the unique differentiable function $f : \mathbb R \to \mathbb C$ that satisfies
$$
f'(x) = if(x),\qquad f(0)=1.
\tag4$$
Then let's try to evaluate the required integrals $(2),(3)$ using integration by parts.
We will do this only using $(4)$.  No complex exponentials appear in what I do below, so I will not accidentally use other properties of $e^{ix}$
Start with $(2)$, integrate by parts, use $(4)$ on the result.  We get
$$
a_n = \frac{-i}{n}\;b_n
\tag5$$
Start with $(3)$ in the same way.  We get
$$
b_n = \frac{i}{n}\;a_n + \frac{(-1)^n}{\pi n}(f(-\pi)-f(\pi))
\tag6$$
Solving the system $(5),(6)$, we get (in case $n \ne 1$)
$$
a_n = \frac{i n (-1)^n}{\pi(n^2-1)}\;(f(\pi)-f(-\pi))
\\
b_n = \frac{n(-1)^n}{\pi(n^2-1)}\;(f(-\pi)-f(\pi))
$$
Unless we can prove $f(\pi) = f(-\pi)$ from the definition $(4)$, it seems we will not be able to complete this.
Now consider $n=1$.  We get equations
$$
b_1 = ia_1
\\
a_1 = a_1 +\frac{i}{\pi}\;(f(\pi)-f(-\pi))
$$
so we conclude $f(\pi)-f(-\pi) = 0$.  This tells us $a_n = b_n = 0$ for $n \ne 1$.  Write $A = a_1$.  Putting this all into $(1)$ we have
$$
f(x) = A\big(\cos(x) + i\sin(x)\big)
\tag7$$
Finally, we evaluate the constant $A$.  For that we use $f(0)=1$
in $(7)$ to get $A=1$.
A: If you allow for complex coefficients, then the Fourier-series of $x\mapsto \cos (x) + \mathrm i \sin(x)$ is just itself (by uniqueness of the Fourier-series).
You can formally compute the Fourier-coefficients of $x\mapsto \mathrm e^{\mathrm i x}$ using integration by parts twice and you obtain (for $k>1$)
$$
a_k = -\frac{2k \sin(k \pi)}{\pi(k^2-1)}=0,
$$
since $k\in\mathbb N$ and $a_0 = 0$ and $a_1 = 1$. The completely similar computation (again for $k>1$) shows
$$
b_k = -\frac{2\mathrm i \sin(k\pi)}{\pi(k^2-1)}=0
$$
and $b_0=0$ and $b_1 =\mathrm i$. Therefore the Forier-series of the two functions agree and they are therefore the same.
EDIT: GEdgar made a very valid point. In order to evaluate the integrals, one can use the ODE she or he had given as mentioned in the comments but one gets another proof of the identity along the way. So I propose another way of doing it:
We use that $f(x) = \mathrm e^{\mathrm i x}$ satisfies the ODE $f' = \mathrm i f$ with the initial datum $f(0)=1$. If $f$ has the Fourier-series
$$
f(x) = \frac{a_0}{2}+\sum_{n=1}^\infty (a_n\cos(nx) + b_n\sin(nx))
$$
you can take a formal derivative and see that
$$
f'(x) = \sum_{n=1}^\infty (-na_n\sin(nx) + nb_n\cos(nx))
$$
Using the ODE above you get $a_0=0$ and the relations (for $n>0$): $- n a_n = \mathrm ib_n$ and $nb_n = \mathrm i a_n$.
From there you get $\mathrm i n^2b_n=\mathrm i b_n$ and therefore $b_n=0$ for $n>1$. Similarly you get $a_n=0$ for $n>1$. If $n=1$ one finds $-a_1=\mathrm ib_1$ and $b_1 = \mathrm i a_1$. But now we know that $f(0) =a_1 = 1$ and therefore $b_1 = \mathrm i$.
