httpin icon indicating copy to clipboard operation
httpin copied to clipboard

Add support for `omitempty` field tag to exclude empty values from queries and headers

Open alecsammon opened this issue 2 months ago • 1 comments

Adds support for an omitempty tag.

Main use case is for query parameters where we may not want have empty keys

i.e. /pets?name_pointer=

By adding omitempty to the tag then this the key will not appear in the query string

i.e.

	type SearchQuery struct {
		NamePointer *string `in:"query=name_pointer,omitempty"`
	}

This will create /pets

This has been added to the formencoder so that it will also remove empty headers.

I have picked omitempty as I feel this will feel most natural for engineers as they are likely already used to this syntax with JSON.

alecsammon avatar May 04 '24 09:05 alecsammon