001/*
002 * Copyright 2022-2025 Revetware LLC.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package com.soklet.core;
018
019import javax.annotation.Nonnull;
020import java.util.Arrays;
021import java.util.Set;
022import java.util.stream.Collectors;
023
024/**
025 * Typesafe representation of <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods">HTTP request methods</a>.
026 *
027 * @author <a href="https://www.revetkn.com">Mark Allen</a>
028 */
029public enum HttpMethod {
030        /**
031         * The HTTP <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET">{@code GET}</a> request method.
032         */
033        GET,
034        /**
035         * The HTTP <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST">{@code POST}</a> request method.
036         */
037        POST,
038        /**
039         * The HTTP <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT">{@code PUT}</a> request method.
040         */
041        PUT,
042        /**
043         * The HTTP <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH">{@code PATCH}</a> request method.
044         */
045        PATCH,
046        /**
047         * The HTTP <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS">{@code OPTIONS}</a> request method.
048         */
049        OPTIONS,
050        /**
051         * The HTTP <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD">{@code HEAD}</a> request method.
052         */
053        HEAD,
054        /**
055         * The HTTP <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE">{@code DELETE}</a> request method.
056         */
057        DELETE;
058
059        @Nonnull
060        private static final Set<HttpMethod> VALUES_AS_SET;
061
062        static {
063                VALUES_AS_SET = Arrays.stream(HttpMethod.values()).collect(Collectors.toUnmodifiableSet());
064        }
065
066        /**
067         * Exposes {@link HttpMethod#values()} as a {@link Set} for convenience.
068         *
069         * @return a {@link Set} representation of this enum's values
070         */
071        @Nonnull
072        public static Set<HttpMethod> valuesAsSet() {
073                return VALUES_AS_SET;
074        }
075}