An easy way to derive the trapezoidal rule (and estimate the error) uses an integration-by-parts.
For a subinterval $[x_{n-1},x_n]$ with $h = x_n - x_{n-1}$ we derive the trapezoidal approximation to the integral and get a local error estimate as follows.
Let $c = (x_{n+1}+x_n)/2$ be the midpoint and note that
$$x_{n+1} - c = c - x_n = \frac{x_{n+1} - x_n}{2} = \frac{h}{2}.$$
Using integration by parts with $u = (x-c)$ and $dv = f'(x)dx$ we get
$$\int_{x_n}^{x_{n+1}}(x-c)f'(x) \, dx = (x-c)f(x)|_{x_n}^{x_{n+1}} - \int_{x_n}^{x_{n+1}} f(x) \, dx \\ = \frac{h}{2} \left(f(x_{n}) + f(x_{n+1}) \right) - \int_{x_n}^{x_{n+1}} f(x) \, dx. $$
Consequently, the local error of the trapezoidal approximation is
$$E = \int_{x_n}^{x_{n+1}}(x-c)f'(x) \, dx. $$
Depending on the smoothness of $f$ and bounds on derivatives this can be used to get more refined estimates.
If the derivative is bounded with $|f'| \leqslant M$ we get the well-known estimate
$$|E| = \left|\frac{h}{2} \left(f(x_{n}) + f(x_{n+1}) \right) - \int_{x_n}^{x_{n+1}} f(x) \, dx \right| \leqslant \frac{M}{4}h^2$$