You can back it up to iCloud. In fact, iCloud Backup is even on by default. If you have more than 5 GB of stuff to back up (as most do), the next tier is 50 GB for a buck a month, or 200 GB for three bucks (and so on). It's very cheap insurance in case of catastrophe such as accidental deletion or a lost/stolen/damaged device (and a nice revenue source for Apple, of course, but that doesn't mean it's not worth it for a safety net for a lot of people's most important stuff nowadays).
With iCloud Backup enabled, your device automatically backs itself up overnight when the display is off and it's connected to power and Wi-Fi; manual backups can also be triggered any time — such as just before you wipe it to send it in for service.
Apple includes these instructions in their servicing kit (the box they send you to send in your phone), and also provides them in person if you drop off the phone at a store; you are specifically asked if you have a backup.