Silkworms can be used to obtain String. The only way to get Silkworms is to use a Crook
on leaves, which has a chance of dropping them. Once you have at least one Silkworm, you can right-click a leaf block to "infest" it. After about 100 seconds, the leaf block will turn into a Cobweb to indicate it's been infested and the infestation will spread out to any leaf blocks touching the infested block every 100 seconds. This continues until there are no more leaf blocks left to infest, so be careful not to accidentally infest any leaves that you don't want converted.
Once infested, you can break the cobweb with a sword to obtain String. You can also break it with a Crook
to obtain both String and another Silkworm, but it will take a long time to break. You can then use 9 String in a Workbench to craft a Cobweb.
Alternatively, you can use either Shears or a sword with the Silk Touch enchantment to obtain the Cobweb directly without having to craft it with String.
You can use Silkworms as compost in a Composter
Silkworms are mainly designed as a way to get started in the Hard Mode