You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

postQuestionRequest.ts 707B

123456789101112131415161718192021222324252627282930
  1. import apiEndpoints from '../apiEndpoints';
  2. import { QuestionData } from '../../utils/interface/questionInterface';
  3. interface QuestionResponse {
  4. message: string;
  5. question: { [key: string]: string };
  6. }
  7. export const postQuestion = async (
  8. questionData: QuestionData
  9. ): Promise<QuestionResponse> => {
  10. const response = await fetch(
  11. `http://localhost:3000${apiEndpoints.question}`,
  12. {
  13. method: 'POST',
  14. body: JSON.stringify(questionData),
  15. headers: {
  16. 'Content-Type': 'application/json',
  17. },
  18. }
  19. );
  20. const data: QuestionResponse = await response.json();
  21. if (!response.ok) {
  22. throw new Error(data.message || 'Something went wrong!');
  23. }
  24. return data;
  25. };