Preheat oven to 400 degrees F. Grease a 9x13-inch baking dish with cooking spray.
In a large pot of salted boiling water, cook green beans for 5 to 7 minutes. Drain water. Pour cooked green beans in the prepared dish in an even layer.
In a medium saucepan, over medium heat, melt butter. Once melted add garlic and stir for 30 seconds. Whisk in flour until smooth. Cook for 1 minute while constantly stirring.
Pour in chicken broth. Stir and cook for 3 minutes.
Next, pour in half-and-half or whole milk. Decrease heat to low and continue to stir and cook until sauce thickens. About 10 minutes. Season sauce with salt and pepper.
Pour sauce evenly over the green beans in dish. Sprinkle the fried onions on top.
Bake in preheated oven for 20 to 25 minutes. *Place a piece of tinfoil over the top the last 10 minutes to prevent onions from burning.*
Remove from oven and let rest 5 minutes or so before serving. Enjoy!